I have three questions.
Is this code actually inserting the text into each vector containers?
If so, is there a faster way fill the containers?
I have a loop commented out because what I tried to do with it did not work. Could someone help me to correct this code?
Thanks in advance
Data.txtCode:#include<iostream> #include <sstream> #include <fstream> #include <vector> #include <iterator> #include <algorithm> using namespace std; vector<int> line_1; vector<int> line_2; vector<int> line_3; void InsertLine( ifstream& ifs, vector<int>& v ) { string s; getline( ifs, s ); istringstream iss( s ); copy( istream_iterator<int>( iss ), istream_iterator<int>(), back_inserter( v ) ); cout << s ; } // { // for (int i = 0; i < v.size(); ++i) // { // cout << " " << v[i] << endl; } } int main() { ifstream ifs( "Data.txt" ); InsertLine( ifs, line_1 ); InsertLine( ifs, line_2 ); InsertLine( ifs, line_3 ); cout<<"\n\n"; system("pause"); system ("CLS"); return main(); }
Code:111 222 yes no



LinkBack URL
About LinkBacks





I used to be an adventurer like you... then I took an arrow to the knee.