小编Evi*_*son的帖子

ofStream错误:写入文本文件?

所以我有这个函数写入文本文件,但我不断得到这个错误,这与使用ofstream的输出语法有关,我相信.有人可以帮我诊断一下吗?

谢谢,

埃文

int writeSave(string chName, string chSex, string chRace, 
              vector<int> chAttributes, int chLevel, int chStage)
{
    ofstream outputFile("saveFile.txt");
    outputFile << "chName: " << chName <<
                  "\nchSex: " << chSex <<
                  "\nchRace: " << chRace <<
                  "\nchAttributes: " << chAttributes <<
                  "\nchLevel: " << chLevel <<
                  "\nchStage: " << chStage;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

运行/home/ubuntu/workspace/saveGame/sgFunc.cpp

/home/ubuntu/workspace/saveGame/sgFunc.cpp: In function ‘int writeSave(std::string, std::string, std::string, std::vector<int>, int, int)’: /home/ubuntu/workspace/saveGame/sgFunc.cpp:27:44: error: cannot bind ‘std::basic_ostream<char>’ lvalue to ‘std::basic_ostream<char>&&’
                     "\nchRace: " << chRace <<
                                            ^

In file …
Run Code Online (Sandbox Code Playgroud)

c++ io file ofstream output

1
推荐指数
1
解决办法
210
查看次数

标签 统计

c++ ×1

file ×1

io ×1

ofstream ×1

output ×1