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