J
Jim Strathmeyer
So I'm having some weird problems with file output. If I try to boil
this problem down to a small, simple program to just show what problems
I'm having, I can't get the same problematic behavior. I have a
function:
bool Tourist::CreateMaps() {
debug.Out() << "Tourist::CreateMaps" << std::endl;
std:fstream out((player_name + ".sav").c_str(),std::ios:ut);
std::string ms = Random::MapStart();
std::string ma = Random::RandomMapArena();
std::string mr = Random::RandomMapRooms(3);
std::string me = Random::MapEnd();
debug.Out() << "mr is " << mr << std::endl;
out << "4\n";
out << ms << std::flush;
out << ma << std::flush;
out << mr << std::flush;
out << me << std::flush;
out.close();
return true;
}
debug.Out returns an ostream & that outputs to a debuggin file. In the
debugging file I see the output of "mr is" and it looks correct.
Specifically, there is a line "3 43 1 33 1 1 0". (For this example,
player_name = "jim".) However, in jim.sav the line "3 33 -1075888520 33
-1075888520 1 0" is written. If I change the std::flush's to
std::endl's, the correct line shows up in jim.sav (but the extra endl's
break the file and it can't be read in correctly.)
Any idea what the heck is going on here? I can't figure out how or why
the line is getting mangled. Any more information I need to provide? The
member function Random::RandomMapRooms returns a string that is build
using a string stream and converted using the str() member.
this problem down to a small, simple program to just show what problems
I'm having, I can't get the same problematic behavior. I have a
function:
bool Tourist::CreateMaps() {
debug.Out() << "Tourist::CreateMaps" << std::endl;
std:fstream out((player_name + ".sav").c_str(),std::ios:ut);
std::string ms = Random::MapStart();
std::string ma = Random::RandomMapArena();
std::string mr = Random::RandomMapRooms(3);
std::string me = Random::MapEnd();
debug.Out() << "mr is " << mr << std::endl;
out << "4\n";
out << ms << std::flush;
out << ma << std::flush;
out << mr << std::flush;
out << me << std::flush;
out.close();
return true;
}
debug.Out returns an ostream & that outputs to a debuggin file. In the
debugging file I see the output of "mr is" and it looks correct.
Specifically, there is a line "3 43 1 33 1 1 0". (For this example,
player_name = "jim".) However, in jim.sav the line "3 33 -1075888520 33
-1075888520 1 0" is written. If I change the std::flush's to
std::endl's, the correct line shows up in jim.sav (but the extra endl's
break the file and it can't be read in correctly.)
Any idea what the heck is going on here? I can't figure out how or why
the line is getting mangled. Any more information I need to provide? The
member function Random::RandomMapRooms returns a string that is build
using a string stream and converted using the str() member.