Can't convert string into float/double

后端 未结 2 429
我在风中等你
我在风中等你 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 );
    }
    

提交回复
热议问题