close

因為istringstream是繼承自ifstream , 

所以我們可以利用ifstream的一些特性 , 輕鬆的在讀取data時 , 轉換到我們所需的type.

假使test.txt的內容為:

string 12345 12.234

也就是說 , 我們希望第一個讀到string , 第二個讀到int , 第三個則是為double的type.

int main()

{

ifstream fin("test.txt");

string str;

getline(fin , str);

stringstream in(str);

string inputStr;

int iValue;

double dValue;

in >> inputStr;

in >> iValue;

in >> double;

return 0;

 

ref : http://www.cplusplus.com/reference/iostream/istringstream/istringstream/

arrow
arrow
    全站熱搜

    JerryCheng 發表在 痞客邦 留言(0) 人氣()