Jump to content
  • Advertisement
Sign in to follow this  

fstream file reading

This topic is 3500 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, I'm trying to read three lines of text from a .txt file for my program. I am using fstream likeso:
char str[1000];
    fstream thefile("File.txt",ios::in);

That reads the text file and places the last piece of text in File.txt into my label. But the problem is that in the File.txt is something like: NumberOne = 5 NumberTwo = 1 NumberThree = 9 I will have variables in my program that will equal the values in the .txt file. So I can't figure out how to read the .txt file and have it look at NumberOne,NumberTwo, and NumberThree and then set the values set in the txt file to a variable in the program. In other words...I'm trying to make it reach each line and pull out the number after the = for each of those. Thanks, Progames25

Share this post

Link to post
Share on other sites
Of course you could write a complex class to read/write variables values in a file, and handle every error cases you will encounter, but what you want to do look very much like an .INI file.

Microsoft provides functions just for reading/writing ini files.
GetPrivateProfileInt is a good start, others function exist for other data type.

Microsoft also decided that INI files are deprecated and shouldn't be used, and recommend using the registry instead to store values. See here for more details.

Finally, I think the best choice is using XML. It's much more powerful and reliable, and there's also a lot of libraries for easy XML manipulation.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!