Hello,
I have a file where the first column shows letters, second column shows numbers.
How could I make it to print everything exactly how it is in the file – a vector/array with strings and integers?
While L B's modification will make that part of the code compile, I don't believe it's a fix. That whole section of code looks dodgy. What is the format of the file you're reading from?
Since you don't have a 2 dimensional array, it's hard to see how they would print a two dimensional array. What you have is one array (or vector) of pairs.
Thank you very much, the code worked very well! Just wanted to ask what exactly this line do? in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
I would like to ask another question. How could I display a file containing big array of letters and numbers?
in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
is the canonical way to discard the rest of a line.
1 2 3 4 5
while ( std::getline(in, nodeValue, ',') && in >> nodeLinks )
{
v.push_back(std::make_pair(nodeValue, nodeLinks)) ;
in.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // prepare for the next getline.
}
Here, for instance, there is (at least) a newline left in the stream after the extraction operations in the loop condition. If the newline were left in the stream, after the next getline, nodeValue would be "\nA" rather than just "A". Probably could've gotten away with in.ignore() ; but being explicit doesn't cost anything, and makes the code a little more forgiving if, for instance, the data file was edited by a human and an extraneous space was placed at the end if the line.
How could I include the titles of stations as appears in the spreadsheet?
I would think you'd be more concerned with how they appeared in the csv. If they don't appear in the csv, nothing is stopping you from modifying the output to resemble the spreadsheet. You may need to read and parse the first line in the file to know the number of columns you need to show, before you actually output the row of "station titles."