String question

Started by
4 comments, last by Gnark 15 years, 11 months ago
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!
Advertisement
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;
Sorry c++
What programming language are you using?

Assuming C:

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

Assuming C++:

inFile >> float1 >> float2 >> float3;
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.
Thanks for the help :)

This topic is closed to new replies.

Advertisement