我在將用戶輸入保存到Txt文件時遇到問題。不知道我做錯了什麼;它不寫入文件:正在讀取和寫入文件流C++
void Menu::nowShowingDecisions()
{
switch (userInput)
{
case 1:
system("cls");
xyPosition(0, 0);
CAtitleHeader();
CAtitleMenu();
getUserInput();
CAtitleDecisions();
break;
return;
case 2:
{
string userName;
string password;
{
ofstream outFile;
{
outFile.open("C:\\Test\\Test.txt");
if (!outFile.good())
cout << "File Could Not Be Opened." << endl;
else
{
cout << "Enter Username:";
cin >> userName;
cout << "Enter Password:";
cin >> password;
while (cin >> userName >> password)
outFile << userName << password << endl;
outFile.close();
}
}
}
return;
{
const int COL_SZ = 10;
ifstream inFile;
inFile.open("C:\\Test\\Test.txt");
if (!inFile.good())
cout << "File could not be opened" << endl;
else
{
cout << left;
cout << "Movie Ticket Accounts" << endl;
cout << setw(COL_SZ) << "User Name" << setw(COL_SZ) << "Password" << endl;
while (inFile >> userName >> password)
{
cout << setw(COL_SZ) << userName << setw(COL_SZ) <<
password << setw(COL_SZ) << endl;
}
inFile.close();
return;
}
}
}
break;
請儘量保持你的Tab鍵是一致的。混淆標籤的代碼很難閱讀。 – user3553031