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;
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With