【发布时间】:2014-04-25 05:52:11
【问题描述】:
我在将用户输入保存到 Txt 文件时遇到问题。不知道我做错了什么;它没有写入文件:
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;
【问题讨论】:
-
请尽量保持标签一致。混沌标签的代码很难阅读。
标签: c++ text file-io filestream