c++ - Textfile to array transfer -


Can anyone help me for a loop that can read from a text file and output to an array?

 for  (int i = 0; i & lt; numCreatures [x]; i ++) {dataFile = organism DT [i]; }   

What I am thinking, but this is wrong.

This is what you can write:

  // Pass the name of the input stream file for your file and if it is opened for you stream datafile ("test.txt"); // Replacement array with a proper container vector & lt; String & gt; Stringlist; // Temporary variables to read lines or words in string mestring; // Continue reading in the temporary variable until you get out of the data (gateline (datafile, msstring)) {// In every repetition, push the value of the temporary variable at the end of the container string list Push_back (mystring); } // Finally, close the file as we do not need it.file.close ();   

I suggest not using raw arrays for this, but appropriate as vector or list and string Standard Library Container . It also depends on the case of your precise use, whether you use the operator & gt; & Gt; want to use overload, or gateline. The former reads a word, while a line will be read later.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -