编写可以输入的文件时遇到麻烦

时间:2015-11-03 01:50:26

标签: c++

这是我的代码:

     void commands(){
    string CMDS = "CMDS";
    cin >> CMDS;
    if(CMDS == "CMDS"){
        cout << "CLS- Clear command line" << endl;
        cout << "Logout- Logs you out of the system" << endl;
        cout << "TFile- Creates a text file" << endl;
        commands();
    }
    else if(CMDS == "CLS"){
        system("cls");
        commands();
    }
    else if(CMDS == "Logout"){
        cout << "Logging out" << endl;
        system("cls");
        Sleep(500);
        mainTitle();
        enterClass();
    }
    else if(CMDS == "TFile"){
        system("cls");
        std::string textf;
        cout << "--Enter Your Text--" << endl;
        ofstream file_;
        file_.open("Text.txt");
        std::getline(std::cin, textf);
        file_ << textf << endl;


        file_.close();
    }
    else{
        cout << "Incorrect choice" << endl;
        commands();
    }
}

我需要帮助才能使它工作,因为std :: getline只是在我尝试编写文本文件后立即关闭程序。该程序假设您允许输入使用空格的文本并创建文本文件。

0 个答案:

没有答案