Need help with stl vectors (?)

T

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.
 
M

Moonlit

Tom said:
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 );
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top