加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 变量’fstream grabpass’具有初始化器但不完整的类型

发布时间:2020-12-16 03:00:12 所属栏目:百科 来源:网络整理
导读:我从使用fstream的文件读取错误,第37行(fstream grabpass(“passwords.txt”);),但似乎没有做错什么. #include iostream#include conio.h#include stringusing namespace std;int i,passcount,asterisks;char replace,value,newchar;string username,passwor
我从使用fstream的文件读取错误,第37行(fstream grabpass(“passwords.txt”);),但似乎没有做错什么.
#include <iostream>
#include <conio.h>
#include <string>

using namespace std;

int i,passcount,asterisks;
char replace,value,newchar;
string username,password,storedUsername,storedPassword;

int login(string username,string password)
{
    if (username=="test"/*storedUsername*/)
    {
        if (password==storedPassword)
        cout<<"Win!";
        else
        cout<<"Username correct,password incorrect.";
    }
    else cout<<"Lose. Wrong username and password.";
}

int main()
{
    cout<<"Username: ";
    cin>>username;
    cout<<"Password: ";
    do
    {
    newchar = getch();
    if (newchar==13)break;
    for (passcount>0;asterisks==passcount;asterisks++)cout<<"*";
    password = password + newchar;
    passcount++;
    } while (passcount!=10);

    fstream grabpass("passwords.txt");
    getline(grabpass,storedPassword);
    grabpass.close();
    login(username,password);

    return 0;
}

解决方法

您需要添加#include< fstream&gt ;.在猜测中,< iostream>可能包括一个fstream的声明(最喜欢通过< iosfwd>),而不是一个定义,因此当您尝试定义该类型的对象时,它具有不完整的类型.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读