变量'fstream grabpass'具有初始值但不完整的类型

时间:2010-11-26 18:42:40

标签: c++

我在第37行使用fstream从文件中读取错误(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;
}

1 个答案:

答案 0 :(得分:20)

您需要添加#include <fstream>。猜测,<iostream>可能包含fstream的声明(最像是<iosfwd>),但不是定义,因此当您尝试定义该对象时,它的类型不完整类型。