Can't convert string into float/double

后端 未结 2 428
我在风中等你
我在风中等你 2021-01-29 06:03

I\'m writing a code for class where I take in input from a huge file (~850 lines) of data separated by commas. what I have so far is:

#include 
         


        
相关标签:
2条回答
  • 2021-01-29 06:23

    You should convert string to float by extracting float from string stream. At present you are using string stream but you are extracting string from it instead of float.

    Try something like this:

    stringstream ss;
    while ( getline( InputFile, DummyLine, ',' ) )
    {
      ss << DummyLine;
    }
    float dummyFloat;
    while ( ss >> dummyFloat )
    {
      Data.push_back( dummyFloat );
    }
    
    0 讨论(0)
  • 2021-01-29 06:31

    Tray this:

    //this can be cause exeptions
    Entry[i].Elevation = atof (Data[((i*10) + 2)].c_str());
    

    NOTE: include cstdlib

    0 讨论(0)
提交回复
热议问题