我在写入文件时遇到问题。如果我用空格写一些东西,它会将每个单词写成一行。为什么?
void backstart()
{
thread t1(backing);
thread t2(thr2);
t1.join();
t2.join();
}
void thr2()
{
string tmp;
tmp = "";
while (tmp != "/exit")
{
cin >> tmp;
if (tmp != "/exit")
{
writefile(tmp);
}
}
runing = false;
}
void writefile(string msg)
{
ofstream myfile("file.txt", ios::out | ios::app);
myfile << userna + ": " + msg + ",\n";
myfile.close();
}
谢谢达蒙