If you are reading whitespace delimited text
, then I wouldn't use get().
This partly depends on the file format and what you want to do with it.
For example, a config or tabular format, I might read into one whole line, using std::getline(istream&, string) and then parse each line into it's constituent parts.
Just for reading a whole load of text though, you could do something like this:
#include <fstream> // for std::ifstream, std:: ofstream
#include <iostream> // for std::cout
#include <string> // for std::string
#include <vector> // for std::vector
#include <iterator> // for std:: ostream_iterator
#include <algorithm> // for std::copy
using namespace std;
// First write some text - I have put tab delimited line and space demited
// lines in
ofs << "Line one using space\nLine\ttwo\tusing\ttab\t\nLine three big spaces no eol";
// Now open the file
// Create a buffer to read the string
// Use a vector to store all the words separately
// Just keep reading until the end of the file (or an error!)
// the operator >> will discard anything that it sees as 'whitespace'
// tab's, spaces, newlines
while( ifs >> tmp )
// This line will just print out every word to stdout
// I put the "#\n" bit, appended after each word, so you can see exactly
// what is in each string (i.e. you will see a '#' at the end of every line)
copy(text.begin(), text.end(), ostream_iterator<string>(cout, "#\n"));