ofstream problems
-
Hi, I am writing a C++ program and am trying to send an array of integers to a text file, however, when I open the text file, it looks like this: ⰸⰶⰰⰹⰲⰰⰰⰰⰰⰰⰰⰲⰴⰶ At an earlier part in the program, I sent an array of integers, but the file came out like I intended it to. I don't know why it doesn't come out correctly for the other piece of code. This is the code that doesn't work correctly:
ofstream game(name.c_str()); if(game.is_open()) { for(int i = 0; i < 81; i++) { game << g_ivalues[i] << ","; } game.close(); }
Please note that all the variable listed are declared. This piece of code does work correctly for me though:ofstream profiles(name.c_str(), ios::out); if(profiles.is_open()) { for(int i = 0; i < 100; i++) { profiles << g_ipuzplayed[i] << ","; } } profiles.close();
Any thoughts on why they don't work the same? Thanks in advance!Chris
-
Hi, I am writing a C++ program and am trying to send an array of integers to a text file, however, when I open the text file, it looks like this: ⰸⰶⰰⰹⰲⰰⰰⰰⰰⰰⰰⰲⰴⰶ At an earlier part in the program, I sent an array of integers, but the file came out like I intended it to. I don't know why it doesn't come out correctly for the other piece of code. This is the code that doesn't work correctly:
ofstream game(name.c_str()); if(game.is_open()) { for(int i = 0; i < 81; i++) { game << g_ivalues[i] << ","; } game.close(); }
Please note that all the variable listed are declared. This piece of code does work correctly for me though:ofstream profiles(name.c_str(), ios::out); if(profiles.is_open()) { for(int i = 0; i < 100; i++) { profiles << g_ipuzplayed[i] << ","; } } profiles.close();
Any thoughts on why they don't work the same? Thanks in advance!Chris
CS925 wrote:
game << g_ivalues[i] << ",";
What is
g_ivalues
? Does the following work?for(int i = 0; i < 81; i++)
{
cout << g_ivalues[i] << ",";
}
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne