I have a file that contains lines as below:
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
First, I store each line with value=1 in the second column as element of a string array. I call the stored elements back via a for-loop, and parse the contents of the element into integers. How does one do that in 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++?
}
Thank you.