Its almost possible with an istream_iterator (3 lines!)
#include <iostream>
#include <fstream>
#include <iterator>
#include <string>
#include <sstream>
using namespace std;
int main()
{
ifstream file("filename.txt");
string fileContents;
copy(istreambuf_iterator<char>(file),
istreambuf_iterator<char>(),
back_inserter(fileContents));
}
Edited - got rid of intermediate string stream, now copies straight into the string, and now using istreambuf_iterator, which ignores whitespace (thanks Martin York for your comment).