以下のような行を含むファイルがあります。
25 1 0 0 0 0
27 1 0 0 0 0
20 0 0 0 0 0
32 1 0 0 0 0
23 1 0 0 0 0
16 0 0 0 0 0
28 1 0 0 0 0
まず、value = 1の各行を、文字列配列の要素として2番目の列に格納します。保存された要素をforループを介して呼び出し、要素の内容を整数に解析します。C ++でそれをどのように行うのですか?
#include <vector>
#include <iostream>
#include <string>
using namespace std;
.....
.....
.....
.....
char line[100];
vector<string> vec_line;
string Vline;
int trimVal, compa, nil0, nil1, nil2, nil3;
......
......
......
//then store lines as strings in vec_line as required by the premise above
// after that, retrieve the contents of the elements of the vector
for (int iline=0; iline<vec_line.size(); iline++) {
cout<<"iline "<<iline<<" vec_line[iline]";
//then I want to parse contents of each string element and store them integer formats
sscanf(vec_line[iline], "%d %d %d %d %d %d", &trimVal, &compa, &nil0, &nil1, &nil2, &nil3); //how would one do this simple parsing task in c and c++?
}
ありがとうございました。