gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 15:22:34 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com