Sign in to follow this  

String question

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

Ok I have this problem: I have a string: string a = "1.0, 0.0, 0.0"; I need to use this string in a method: Point3D(a); And this is how the method is used: Point3d(float x, float y, float z) Obviously I can't do Point3D(a), but I have no idea how to fix this. Reason I need this is because I'm reading from a file. Please help!

Share this post


Link to post
Share on other sites
What language?

Assuming C++, why don't you just read in the values from file as floats?


std::ifstream infile(filename);

float x, y, z;
infile >> x;
infile >> y;
infile >> z;

Share this post


Link to post
Share on other sites
What programming language are you using?

Assuming C:

fscanf (fp, "%f %f %f", &float1, &float2, &float3);

Assuming C++:

inFile >> float1 >> float2 >> float3;

Share this post


Link to post
Share on other sites
Just a note to fpsgamers post that if you are going to use a function like fscanf and scanf() microsoft has deprecated them and replaced them with newer safer functions they are virtual named the same and just prefixed like so s_sfscanf() or its post fixed i am fairly certain it is prefixed.The s_ i belive stands for safe just search on msdn.com to be sure. For the most part the functions have stayed unchanged as for arugments and work the same its the internals that have been made safer.

Regards Jouei.

Share this post


Link to post
Share on other sites

This topic is 3493 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.

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