Alex Rivera | Logout

using fstream to read every character including spaces and newline

Asked 2008-09-22T19:26:06.103
35

I wanted to use fstream to read a txt file.

I am using inFile >> characterToConvert, but the problem is that this omits any spaces and newline.

I am writing an encryption program so I need to include the spaces and newlines.

What would be the proper way to go about accomplishing this?

Edit
Report

1 Answer

0
ifstream ifile(path);
std::string contents((std::istreambuf_iterator<char>(ifile)), std::istreambuf_iterator<char>());
ifile.close();
answered 2012-07-21T08:58:32.680

Your Answer