Jump to content
  • Advertisement
Sign in to follow this  
Edzio

C++ unix aka wumpus project - need a file-finder

This topic is 4216 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello again, I'm stuck on a file loading problem; i need to load an unknown sequential access filename (.txt) and am having trouble with where to assign the variables. this is inside my commandline args : if ((string(argv[1]) == "-f") && (string(argv[2]) == " ")) { ifstream infile; cout << "Sorry, not working yet!" << endl; } else... ? ifstream infile; string filename = ? infile .open(variable?.c_str()) please help

Share this post


Link to post
Share on other sites
Advertisement
If using an invocation like

myapp -f filename.txt

then argv[1] will be "-f" and argv[2] will be "filename.txt". The white space in-between will be already dropped. So your check about argv[2] seems me not correct. I would expect something like

if ( argc >= 3 && string(argv[1]) == "-f" ) {
ifstream infile;
infile.open(argv[2]);
...
}
else ...


to be the way to go. It checks whether argc is at least 3 and hence argv[1] and argv[2] are available. Then it checks whether the "-f" option is given. If true it expects the following argument to be a filename and passes it into the open method.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!