Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

variable 'fstream grabpass' has initializer but incomplete type

Tags:

c++

I'm getting an error reading from a file using fstream, on line 37 (fstream grabpass("passwords.txt");) but doesn't seem like I'm doing anything wrong.

#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;
}
like image 331
Captain Lightning Avatar asked Nov 26 '10 18:11

Captain Lightning


1 Answers

You need to add #include <fstream>. At a guess, <iostream> is probably including a declaration of fstream (most like via <iosfwd>), but not a definition, so it has incomplete type when you try to define an object of that type.

like image 90
Jerry Coffin Avatar answered Nov 15 '22 19:11

Jerry Coffin