This is my first post so if I have written or formated something against forums rules please show some understanding. I also happens to be a novice programmer in C++ so if you could please write somewhat simplified if possible.
I need to read some values from a file named text.txt which is like that (total 13 columns):
1 2 B5 AA 120 0 100 1.5 1.5 G 0 0 0 \n 1 2 B6 AB 120 0 100 1.5 1.5 G 0 0 0 \n 1 2 B7 AC 120 0 100 1.5 1.5 G 0 0 0 \n ... The above file can have an undetermined number of lines. It is generated through an other routine.
I made a routine in code::blocks. I have made three matrices holding the above data as integers, doubles, strings. The deceleration I have made is as follows:
int c1, c2, c7, i = 0, nNumPipes; double c5, c6, c8, c9, c11, c12, c13; string c3, c4, c10; int PipeI[][3] = {0}; double PipeD[][6] = {0}; string PipeS[10000][3]; Then I use the following syntax to read the lines:
ifstream inf("C:\\text.txt"); while (inf >> c1 >> c2 >> c3 >> c4 >> c5 >> c6 >> c7 >> c8 >> c9 >> c10 >> c11 >> c12 >> c13) { PipeI[i][0] = c1; PipeI[i][1] = c2; PipeS[i][0] = c3; PipeS[i][1] = c4; PipeD[i][2] = c5; PipeI[i][2] = c7; PipeD[i][0] = c8; PipeD[i][1] = c9; PipeS[i][2] = c10; PipeD[i][5] = c11; PipeD[i][3] = c12; PipeD[i][4] = c13; i++; } nNumPipes = i; The code however fails in this 'while' loop. Do I miss something?
The error message I get is a window saying "xxx.exe has stop working".
Any help will be appreciated.
PipeIand PipeD` don't make sense. Rather than several snippets you should construct a short complete example. Based on the code you've shown and described it shouldn't be much longer but it might point out subtle issues we can't see now.std::vector<>) and a struct for each of the data records to read.string PipeS[10000][3]is a rather large amount of memory to allocate on the stack (240kB on my platform). This would be better done dynamically, i.e. usingstd::vectoras πάντα ῥεῖ already mentioned.