9
我在使用fstream的第37行(fstream grabpass(「passwords.txt」);)中看到一個錯誤讀取,但似乎並不像我做錯任何事情。變量'fstream grabpass'有初始值設定項但是不完整類型
#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;
}
呃。我爲什麼沒有這樣做......謝謝,傑瑞。我的一個愚蠢的錯誤。 – 2010-11-26 18:49:08