我可以讓文件保存正確,但我似乎無法得到多個單詞寫入.txt,就像我輸入「Hi purple」它只是寫「Hi」,在這裏是代碼如何在C++中打印多個單詞
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
system("color F0");
string name0;
cout << "Please enter a file name, no spaces/special characters" << endl;
cin >> name0;
name0 = name0+".txt";
system("cls");
cout << " FISHSOFT" << endl;
cout << "The best text editor in the world" << endl << endl;
string text;
cin >> text;
ofstream myfile;
myfile.open (name0.c_str() , ios::out | ios::trunc);
myfile << text;
myfile.close();
system("PAUSE");
return 0;
}
它是'std :: getline',帶有小寫字母L.並且該函數不返回字符串,而是接受字符串引用。 –
謝謝,解決了。 –