Таким образом, у меня есть эта функция, которая записывает в текстовый файл, но я продолжаю получать эту ошибку, которая имеет какое-то отношение к синтаксису вывода из используемого потока, на который я верю. Может ли кто-нибудь помочь диагностировать это для меня?ofStream error: запись в текстовый файл?
Спасибо,
Эвин
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;
}
Запуск /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 included from /usr/include/c++/4.8/iostream:39:0,
from /home/ubuntu/workspace/saveGame/sgFunc.cpp:1: /usr/include/c++/4.8/ostream:602:5: error: initializing argument 1 of ‘std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = std::vector<int>]’
operator<<(basic_ostream<_CharT, _Traits>&& __os, const _Tp& __x)
^
Если вы не переопределили '' '' оператор для 'векторов', вы не можете просто сделать' << chAttributes' –