Jump to content
  • Advertisement
Sign in to follow this  

reading in a file

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

i would like to read some values in a text file and use these values as object coordinate components in my application. the function that reads the file returns a char table. for instance : if a file contains a value of -1.0f the reading function will return a char table organised like that: table[0]=- table[1]=1 table[2]=. table[3]=0 table[4]=f As you can see, i can't use these values like that. I'm looking for a method which could allow me to transform theses char and recover the real value ?

Share this post

Link to post
Share on other sites
Writing a function or method to do this yourself is trivial and would be a good excercise. Unfortunately I can't offer any direct solution though as I have always used my own functions for this.

I am unsure whether or not the strtol()/strtof() functions are part of the standard and may be undefined by the standard.

Share this post

Link to post
Share on other sites

1) open file
2) copy whole contents into one string container

hope this helps:

#include <fstream>
//copy file to existing_string
std::ifstream config( para_configPath.c_str() );
print::Instance().Error( "no_file", para_configPath );
std::ifstream file(filename);
existing_string.assign(std::istreambuf_iterator< char >(file), std::istreambuf_iterator< char >());


use your i/o class and convert it. (probably will be slower than the above)

for( int i=0; i<Table.length(); i++ )

std::cout << somestring;

hope that was helpful.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!