Hey I am quite new to C++ and I am facing a problem:
I have a textfile which looks like this:
500
1120
10
number1,1 number1,2 ... number1,500
number2,1
.
.
number1120,1
So the first two values on top of the text-file describe the dimensions of the matrix. I now want to write a code, which reads all the files from the matrix into an array or vector of int
values. I can read the first three values (500, 1120,10) and write them into an integer value using getline
and stringstream
, but I can't figure out how to read the matrix tap separated with a loop.
You may consider to read the matrix line by line with a loop, and split the current line using a tokenizer (e.g.
std::strtok
) or a nested loop that splits the line at your delimiters. There is a thread about tokenizers.