I have to read txt file which data is number. For example, my txt file is
"1 2 3 4
2 3 4 5 6 7"
that is it has to rows and each row has different number of column.
I'd like to keep it in 2 dimentional array,
vector< vector<float>> vec(2,vector<float>). So I use function "strtok" to seperate my data when it find " ", and use function "atof" to convert char into float. However, when I try to puch the number into my vector, it continue to push all data into one row. My vector now is [1 2 3 4 2 3 4 5 6 7]. How can I write my code to start a new row when it goes to the end of previous row. I hope my vector looks like
[1 2 3 4
2 3 4 5 6 7]
Why so complicated? Just read the numbers as numbers.
To identify a row you could read the line in a string, pass it to a stringstream and then read as numbers.