Note that there are some explanatory texts on larger screens.

plurals
  1. PORead File, jump lines and store data in array.
    primarykey
    data
    text
    <p>I am kind of new to C++ and I have a problem with my program. I have looked for hours and days and even though there are a lot of posts similar to this one, I can't figure out why my program doesn't work.</p> <p>I have a file that contains data in this way.</p> <p>STRING FLOAT FLOAT </p> <p>STRING INT</p> <p>STRING FLOAT FLOAT FLOAT</p> <p>STRING INT INT </p> <p>FLOAT</p> <p>FLOAT ...</p> <p>So the first few lines have string for the first column and number for the rest, and at some point there are just float number. </p> <p>I have managed to get the data up to where all the floats start but I can't figure out how to store the rest of number in an array. (I KNOW IT WOULD BE A LOT EASIER TO DO IT WITH VECTOR BUT I HAVE TO DO IT WITH ARRAYS).</p> <p>This is what I have done. </p> <pre><code>void getData(string *ext, int size) { istringstream is(*ext); float val; is &gt;&gt; val; float *arrVal = new float[10]; // I dont know the size of the Array. if(typeid(val) == typeid(float)) //IM NOT SURE ABOUT THIS AT ALL. I JUST DON'T KNOW HOW TO GET TO THE LINE WHERE THERE ARE NO STRINGS { arr[size] = atof(*ext.c_str()); } // I think this part is why it does not work. int main() { ifstream File("t.txt"); string line; int nLines(0); float *arrayValues = new float[12]; if(!inFile) { cerr &lt;&lt; "Cannot open file." &lt;&lt; endl; return -1; } else { while(getline(File, line)) { getValues(&amp;line, nLines); getPoints(&amp;line); //this function gets the values of the first lines. ++nLines; } } system("pause"); return 0; } </code></pre> <p>So basically I have to figure out how to jump to the line where all the floats start and how to store those in an array. I am sure there is a bunch of errors. I hope you guys get what I am trying to do. I really have looked everywhere and can't find anything.</p> <p>Thank you !!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload