2014-01-27 85 views
0

我有一大堆CSV行,我逐行分解,用逗號分開,並將這些標記放入向量中。將字符串轉換爲C++中的push_back之前的float float

下面是一些代碼片段,我處理在句子中的最後兩個項目:

//token for parser 
     string token; 

     //turn into a string stream 
     istringstream ss(line); 

     //ye olde vector to put things in 
     std::vector<float> lineContainer; 
     while(getline(ss, token, ',')) 
     { 
      lineContainer.push_back(::atof(token)); 
     } 

當我嘗試編譯,我得到以下幾點:

Error: cannot convert 'std::string' to "const char*' for argument '1' to 'double atof(const char*)'. 

換句話說,轉換字符串浮動是一個不,不,至少我是如何做到這一點。

如何將此數據類型轉換爲浮點型?我認爲這將是直截了當的,但我對C++非常缺乏經驗(我承諾在C#中更好),並且還沒有捕獲我認爲在其他語言中理所當然的所有細微差別。

+0

可能重複(http://stackoverflow.com/questions/1012571/stdstring-to-float-or-double) – kfsone

回答

相關問題