C++ 读写文件流C++;

C++ 读写文件流C++;,c++,text,file-io,filestream,C++,Text,File Io,Filestream,我在将用户输入保存到Txt文件中时遇到问题。不知道我做错了什么;它没有写入文件: void Menu::nowShowingDecisions() { switch (userInput) { case 1: system("cls"); xyPosition(0, 0); CAtitleHeader(); CAtitleMenu(); getUserInput(); CAti

我在将用户输入保存到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;
void菜单::nowShowingDecisions()
{
开关(用户输入)
{
案例1:
系统(“cls”);
xyPosition(0,0);
CAtitleHeader();
CAtitleMenu();
getUserInput();
CAtitleDecisions();
打破
返回;
案例2:
{
字符串用户名;
字符串密码;
{
出流孔的直径;
{
outFile.open(“C:\\Test\\Test.txt”);
如果(!outFile.good())
密码;
while(cin>>用户名>>密码)
在此代码块中输出文件

             cout << "Enter Username:";
              cin >> userName;             // BEING IGNORED

              cout << "Enter Password:";
              cin >> password;             // BEING IGNORED
              while (cin >> userName >> password) // THIS IS BEING SAVED>
                  outFile << userName << password << endl;

<>使用C++编写或编写一个TXT可以用这样简单的方式完成。 //在文本文件上写入

 #include <iostream>
 #include <fstream>

 using namespace std;

 int main () 

 {
   ofstream myfile ("example.txt");

    if (myfile.is_open())
 {
    myfile << "This is a line.\n";
    myfile << "This is another line.\n";
   myfile.close();
 }
   else cout << "Unable to open file";
    return 0;
}
 #include <iostream>
 #include <fstream>
 #include <string>
 using namespace std;

 int main () 

 {
   string line;
   ifstream myfile ("example.txt");
  if (myfile.is_open())
  {
    while ( getline (myfile,line) )
   {
      cout << line << '\n';
    }
  myfile.close();
 }

  else cout << "Unable to open file"; 

 return 0;
 }
#包括
#包括
使用名称空间std;
int main()
{
流myfile(“example.txt”);
如果(myfile.is_open())
{

我的文件请尽量保持标签的一致性。混乱的标签代码很难阅读。非常感谢!在while循环中被弄糊涂了
 #include <iostream>
 #include <fstream>
 #include <string>
 using namespace std;

 int main () 

 {
   string line;
   ifstream myfile ("example.txt");
  if (myfile.is_open())
  {
    while ( getline (myfile,line) )
   {
      cout << line << '\n';
    }
  myfile.close();
 }

  else cout << "Unable to open file"; 

 return 0;
 }