Hello there. I'm currently solving problem of parsing txt file. That file looks like this:
Voltage 5
//ID Type Vn V Theta[rad]
0 1 1 1 0
1 0 1 1 0
2 0 1 0 1
3 0 1 1 1
4 0 1 0 0
//some lines of comments
//additional text
Lines 3
//description of values
0 3 4
So, my problem is that I could read data only for Voltage, and my program stops the read next lines of data. I would like to ignore next 4 rows after Voltage, and continue to read data for Lines. Any help would be higly appreciate.
This is my code...
stringstream ss;
ifstream file;
string line,name;
int num;
ifstream values ( "values.txt", std::ios::in); //opening file
while(getline(values,line)) // Reads lines into line
{
ss.str(line); // Use s as source of input.
ss>>name>>num;
getline(values,line);
if(name == "Voltage")
{
int _id=0;
int _type=0;
int _Vn;
float _V,_Theta;
for (int i=0;i<num;i++)
{
getline(values, line);
ss.clear();
ss.str(line);
if(line.substr(0,2) !="//")
{
ss >> _id >>_type>>_Vn>>_V>>_Theta;
}
}
}
elseif(name == "Lines")
{
cout<<"I found the lines data !";
}