Also habe ich diese Funktion, die in eine Textdatei schreibt, aber ich bekomme diesen Fehler, der etwas mit der Syntax der Ausgabe von ofstream zu tun hat glaube ich. Kann jemand helfen, das für mich zu diagnostizieren?ofStream-Fehler: Schreiben in Textdatei?
Danke,
Evin
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;
}
Lauf /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)
^
Wenn Sie den Operator '<<' nicht für 'Vektoren' neu definiert haben, können Sie' 'chAttributes' 'nicht einfach tun –