c++ - 你如何在C++中将两个字符串写入一个文件

标签 c++

{
    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/

相关文章:

c++ - 有没有办法总结数组的位位置?

c++ - PostgreSQL 向 C++ 应用程序发出警报

c++ - 读取文件: How file pointer is moved using fscanf and how scanf/fscanf work with missing %type

c++ - 无法将父类(super class)转换为子类

c++ - 在使用 eof() 的 while 循环中因一个错误而关闭

c++ - `enable_if()` 禁用模板类的静态成员函数声明

c++ - MonthOf TDateTime 歧义

c++ - LD_DEBUG 输出中的 "calling init:"是什么?

c++ - 使用 boost::future::then 在主线程中执行

c++ - 为什么数组模板迭代器声明需要指定数组大小?