stirng 解析的问题
大家好 我要写一段解析string的代码 来解析从文件中读进来的每一行数据 例如
1 6.0 -11.5 19 90 1
2 -11.0 -18.5 25 -36 3
……
我的写的代码 把每行的第一列读出来放在一个单独的vector里 再把每行后面的四列读出来放在一个vector里
- C/C++ code
while ( getline(in, strTemp, '\n')) { vecRecords.clear(); nKind = atoi(strTemp.substr(0, strTemp.find(" ")).c_str()); vecKind.push_back(nKind); strTemp = strTemp.substr( strTemp.find_first_of(" ") + 1); strTemp = strTemp.substr( strTemp.find_first_not_of(" ")); while ( strTemp.find_first_not_of(" ") != -1 ) { dValue = atof(strTemp.substr(strTemp.find_first_not_of(" "), strTemp.find(" ")).c_str()); vecRecords.push_back(dValue); strTemp = strTemp.substr( strTemp.find_first_of(" ") + 1); strTemp = strTemp.substr( strTemp.find_first_not_of(' ')); }……现在的问题是 我读取每一行的时候 第二列以后的每一列如果由多个空格隔开 我这么判断会有问题 谁有什么好办法来解析string里的单词啊
[解决办法]
用stringstream