1 sec, there's a perfect solution for you. You will probably want to download the Boost library (www.boost.org) to get its string tokenizer classes (makes the program simpler; not strictly necessary but otherwise you'll have to search for line breaks yourself). One more question: If you're going through, line by line, do you want to know when blank lines happen, or would you rather only get each non-blank line?

This just prints each token; during the for loop, *tok_iter is a string which has the current line. This keeps all whitespace and empty lines are kept (they're the null string "").

If you're using unicode files, just change string to wstring, char to wchar_t, and you should be fine.

Oh, and the extra parentheses around the first parameter of the construction of std::string file ARE needed. It's necessary to parse correctly.

There are many, many ways to accomplish this. I like this because it doesn't rely on arrays at all; buffer overrun is not an issue. You need to know nothing at all about the line length or line count of the file. There are no dangers of leaking resources; we never directly use arrays or pointers, and we never directly allocate memory dynamically.

This essentially creates a vector of strings, where each string is a line. This has the advantage of easily finding numbered lines (e.g. file[12] will give the 13th line of the file). It has less power in that it can't separate the file into tokens based on arbitrary delimiters (like the first code would), and you also don't have one string that contains the entirety of the file, but if you don't need these, the above code is certainly doable.

It has the same advantages -- no possibility of buffer overrun, no worries about dynamic memory allocation, no arrays, no memory we need to explicitly release.