Thursday 15 March 2012

Formatted file reading with C++ -


I am trying to read all the integers from a file and put it in an array. I have an input file that contains integer in the following format:

  3 74 74 1 1 74 8 76   

Actually, one in each line Number is, one place, then another number I know in Java that I can use the next scanner method to ignore spacing, but I did not find any such function in C ++.

#include > i) arr.push_back (i); }

Or, using standard algorithms:

  #include & lt; Algorithm & gt; # Include & lt; Fstream & gt; #include & lt; Iterator & gt; # Include & lt; Vector & gt; Int main () {std :: vector & lt; Int & gt; Arrival; Std :: ifstream f ("file.txt"); Std :: copy (std :: istream_iterator & lt; int & gt; (f), std :: istream_iterator & lt; int & gt; (), std :: back_inserter (arr)); }    

No comments:

Post a Comment