c++ - 变量 'fstream grabpass' 具有初始值设定项但类型不完整

标签 c++

我在第 37 行(fstream grabpass("passwords.txt");)上使用 fstream 从文件中读取错误,但似乎我做错了什么。

#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> .猜测,<iostream>可能包括 fstream 的声明(最像通过 <iosfwd> ),但不是定义,因此当您尝试定义该类型的对象时它的类型不完整。

关于c++ - 变量 'fstream grabpass' 具有初始值设定项但类型不完整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4287806/

相关文章:

c++ - C++ 中 Queue<T> 的限制大小

c++ - 带有嵌套 if-else 的循环的时间复杂度

c++ - 基于方法的特化模板

c++ - 在构造函数中分配双向链表指针

c++ - STL iota 包含文件更改

c++ - 从文件加载矩阵

C++ 流二次插入运算符

c++ - 如果没有打开 RTTI,C++ 中的 dynamic_cast 将无法工作;为什么?

c++ - 程序有问题吗

c++ - C++中的静态数组忘记了它的大小