Jump to content
  • Advertisement
Sign in to follow this  
l jsym l

Input File in C++

This topic is 2600 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

Hey, I'm trying to read in an input file for a program that I am creating and am running into some problems. The way I have it set up right now is working but it could be troublesome in the future.
I was just wondering if there was a way to read in a input file such as:
FFFFFFFF M LLLLLLLLLL
John T Smith

What I want to do is read in these strings separately according to the column widths (i.e FFFFFFF M LLLLLLLLLL) I know I could use a substring for these, however, when I have to use them in the future
I dont want to have something like if ( a == "John ") instead I want if (a == "John") without the extra bits at the end.

I am unsure if I am explaining myself clear enough or not but I tried my best to make it understandable.

Share this post


Link to post
Share on other sites
Advertisement

Hey, I'm trying to read in an input file for a program that I am creating and am running into some problems. The way I have it set up right now is working but it could be troublesome in the future.
I was just wondering if there was a way to read in a input file such as:
FFFFFFFF M LLLLLLLLLL
John T Smith

What I want to do is read in these strings separately according to the column widths (i.e FFFFFFF M LLLLLLLLLL) I know I could use a substring for these, however, when I have to use them in the future
I dont want to have something like if ( a == "John ") instead I want if (a == "John") without the extra bits at the end.

I am unsure if I am explaining myself clear enough or not but I tried my best to make it understandable.


If you input the whole line into either a character array or a string you can just loop through each character, and when you hit a space copy everything from after the last space until the space you just reached.
Or with std::string there are easier ways to find spaces and cut things out etc.

or you could use something like strtok strtok

Share this post


Link to post
Share on other sites
wut yewbie said, or use std::regex (or boost::regex if you do not yet live in the second decade of the 21st century).

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!