I am very new in C++. I have a question concerning reading an input file, where I have to create a matrix from same elements of the data if a condition is fullfilled.
Here is my input files (matrix.txt)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
This is a line, below is another line with numbers
0.15 10.1
*M
2.5 3.01 4.11
*M
6.16 7.17 8.01
*M
10.16 11.133 12.12
*M
14.17 15.110 16.16
Reading should stop in this line
another line
another line
15.0 12.015 13.001
Since you know it's 4 lines of numbers. Couldnt you use a for-loop that runs 4 times and reads in all the numbers, that way it will stop where you want it to, no?
Well then, you can first read the file word by word, using std::cin instead of std::getline. If word is word is ever equal to *M you know that the next line will be numbers. So after you've read 14.17 15.110 16.16 and attempt to read in the next word, if it's not *M, then ignore it. Does that make sense?
Sure I can post the code.
I slightly changed input file (by adding & after each row). Here is the new input file with and the code.
Have a great weekend!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
This is a line, below is another line with numbers
0.15 10.1
*M
2.5 3.01 4.11
&
*M
6.16 7.17 8.01
&
*M
10.16 11.133 12.12
&
*M
14.17 15.110 16.16
Reading should stop in this line
another line
another line
15.0 12.015 13.001