Sign in to follow this  

reading in a file

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this