Essentially I have a file that goes like this
Number of entries
Id
Name of entry
Float of entry
Series of numbers
Id
Name of entry
Float of entry
Series of numbers
For example, a file would look like this
4
0
A. com
0. 0
1 2 3
1
B. com
0. 0
0 3
2
C. com
0. 0
0 1
3
D. com
0. 0
1
Essentially what I want to do is to
- extract the first number, which tells me how many entries there will be.
- For that many times, extract the following
- Extract a string
- Extract a double
- Extract a series of numbers
I'm ok with the first few, but it's the last part that stumps me. I don't know how many numbers will be below the float. It could be one, two, or a hundred. Here is the code I've written:
ifstream ifile(filename);
if(ifile.fail()){
return false;
}
ifile >> num_of_webpages;
for(int i=0; i < num_of_webpages; i++){
Page temp;
ifile >> pageid;
ifile >> page_URL;
ifile >> pagerank;
string myline;
getline(ifile, myline);
stringstream ss(myline);
while(ss >> outgoing_link){
temp.add_url_to_links(outgoing_link);
cout << outgoing_link << endl;
}
}
I can't extract it line by line because the types I'm extracting aren't all the same. If I'm already extracting info from a file, how do I extract the next line, then use that to extract the numbers until the end of the next line?