By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,189 Members | 903 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,189 IT Pros & Developers. It's quick & easy.

Need help with stl vectors (?)

P: n/a
Tom
How do you get the whole line and put it in a vector from a txt file,
I would like to first get a line, store it to the first element in a
vector and then keep on doing this until the end of the file is
reached. I would appreciate it if anyone helped me.
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Tom" <sn***@hotmail.com> wrote in message
news:78**************************@posting.google.c om...
How do you get the whole line and put it in a vector from a txt file,
I would like to first get a line, store it to the first element in a
vector and then keep on doing this until the end of the file is
reached. I would appreciate it if anyone helped me.


#include <fstream>
#include <string>
#include <vector>

using namespace std;

ifstream Input( "somefile.txt" );
string Line;
vector<string> Txt;

while( getline( Input, Line ) )
{
Txt.push_back( Line );
}
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.