|
-
February 7th, 2009, 10:15 AM
#2
Re: Problem opening blank files with ifstream
I figured it out. Here is the updated code:
Here is updated code that works great for my save game function in my game just in case anyone has similar problems to this in the future and stumbles upon this on the google or something
Code:
#include <string>
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
int main()
{
int tmpInt =0;
string tmpString;
string stringArray[4];
stringArray[0] = "empty";
stringArray[1] = "empty";
stringArray[2] = "empty";
stringArray[3] = "empty";
ifstream myStream("SAVEGAME.DAT");
while(!(myStream.peek() == EOF))
{
getline(myStream, tmpString);
stringArray[tmpInt] = tmpString;
tmpInt++;
}
for (tmpInt = 0; tmpInt < 4; tmpInt++)
{
cout << stringArray[tmpInt] << endl;
}
myStream.clear();
myStream.close();
system("PAUSE");
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|