Opening a text file
Well for my final project I have to make a game and whatnot, that is kinda not the issue. The issue is how to get my .txt file open so people can read it. I've tried looking it up, but I must be doing something wrong, it keeps talking about file I/O (I guess as it should be), but I just want to be able to have my .txt file pop up when I click the button for the help file.
So, you don't want your program to read the file, you want your user to read the file? I would guess this would have to be platform-specific; in Windows I think it's ShellExecute to open a text file using whatever the user's standard text-file-opener-program is.
Well I know in some games I've played they had it thatn when you click their button for help it would open a .txt file. I was hoping I could do the same, it doesn't sound like it though.
So, I take it you want your game to DISPLAY a particular text-file?
Originally Posted by bwisdom
If so, you need to read the file (using for example istream::getline()) and then display the text from that line. Keep going until the getline fails [at end of file].
Should be possible to do in about 4-6 lines of code.
Like matsp sufggested, somthing like the below would be similar to a loop you could develop.
inFile being the name of the file to read in. But remember to open and close the file ;)
while ( std::getline( inFile, line ))
std::cout<< line << std::endl;
For windows, try system("type -FILENAME-");
Oh awesome, so there is hope. The only reason I don't want to do it the windows way is because even though I am creating on a windows machine the project is going to be compiled and ran for a grade on a unix machine.
Thank you all for the help. Ill try out this method and see how it goes.