edit: need some help

May 8, 2013 at 6:04am
Thank you!
Last edited on May 9, 2013 at 10:59pm
May 8, 2013 at 8:12am
Well, a solution(probably easyer) would be to just read the whole line first, then separate the line in 3 parts, based on the ",".
Then you convert the 2 string variables to floats using atof
Reference to atof = http://www.cplusplus.com/reference/cstdlib/atof/?kw=atof
Something like this
Please note that the code might have some errors(probably typing since it was writen directly in the browser on this page)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
ifstream fIn("file.in");
if(fIn.is_open())
{
  while(fIn.good())
  {
    string line;
    getline(fIn, line);
    string firstFloat = line.substr(0, (line.find_first_of(",") - 1)); // this assignts to firstFloat the value of the first number by copying from the beginning to the position of the coma - 1 because you don't want to include the coma as well
    string secondFloat = line.substr((line.find_last_of(",") + 1),  string::npos); // the second float number
    float f1 = atof(firstFloat.c_str());
    float f2 = atof(secondFloat.c_str());
    .....
    and the rest of your code doing what you want with the 3 values.
    also note that i didn't extract the city name but you can do it the same way using substr and the position of the 2 commas. 
Last edited on May 8, 2013 at 8:13am
May 9, 2013 at 10:15pm
Thanks! Got a clean conversion now but I need a better while loop, mine does nothing. Anyway you can help?
May 11, 2013 at 4:46pm
About what while loop are you talking about?
You don't have any more code posted.
May 11, 2013 at 5:47pm
the one he deleted so somebody could not see it. same with his thread he started called "Good stuff" and all it says is good stuff so I wouldn't even bother helping him
Last edited on May 11, 2013 at 5:48pm
May 15, 2013 at 12:28am
I figured out another solution thank you nedo.
Last edited on May 15, 2013 at 12:29am
May 15, 2013 at 12:33am
@nedo: you are stopping too late
while( geline(input, line) )
Topic archived. No new replies allowed.