{
string vertexcharacter = "{";
string a = "}";
ofstream myfile;
myfile.open("newfile.txt");
myfile << vertexcharacter, a;
myfile.close();
system("pause");
return 0;
第一个字符串已写入但第二个字符串未显示在文本文档中
最佳答案
您似乎在寻找:
myfile << vertexcharacter << a;
目前,您使用的是逗号运算符,因此您的行等同于:
(myfile << vertexcharacter), a;
这会将 vertexcharacter
插入到 myfile
中,丢弃结果,然后计算什么都不做的 a
。
关于c++ - 你如何在C++中将两个字符串写入一个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15578880/