![]() |
| | #1 |
| Registered User Join Date: Aug 2006 Location: Liverpool UK
Posts: 452
| Save function not working Code: void SolBoard::SaveGame(int myfile)
{
ofstream Gamefile;
if(myfile == 0) //which file to write over.
ofstream Gamefile("mysave0.txt");
if(myfile == 1)
ofstream Gamefile("mysave1.txt");
if(myfile == 2)
ofstream Gamefile("mysave2.txt");
for(countclick = 0; countclick < 49; countclick++)
{
Gamefile << moves_record[moves][countclick];
Gamefile<< " ";
}
Gamefile.close();
}
|
| rogster001 is offline | |
| | #2 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 11,341
| You should be using the open() member function instead of creating a new ofstream object in a scope local to the respective if statements. You should also consider what happens if myfile contains none of the values listed.
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is online now | |
| | #3 |
| Registered User Join Date: Aug 2006 Location: Liverpool UK
Posts: 452
| ok thanks i will look up the function, i know i should put the error checking in too, file i/o does my swede in. |
| rogster001 is offline | |
| | #4 |
| Registered User Join Date: Aug 2006 Location: Liverpool UK
Posts: 452
| i got it, nice ta |
| rogster001 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Getting an error with OpenGL: collect2: ld returned 1 exit status | Lorgon Jortle | C++ Programming | 6 | 05-08-2009 08:18 PM |
| Which Library Files for these unreferenced functions? | lehe | C++ Programming | 3 | 01-31-2009 10:30 PM |
| Compiling sample DarkGDK Program | Phyxashun | Game Programming | 6 | 01-27-2009 03:07 AM |
| Seg Fault in Compare Function | tytelizgal | C Programming | 1 | 10-25-2008 03:06 PM |
| Troubleshooting Input Function | SiliconHobo | C Programming | 14 | 12-05-2007 07:18 AM |