I have the following simple code to read a file:
std::basic_ifstream<wchar_t> RFile(L"C:\\file.exe", std::ios::binary|std::ios::ate);
if (!RFile.is_open()){ cout << "Cannot open the file." << endl; return 0;}
std::streamoff fileSize = RFile.tellg();
wstring fileContent;
fileContent.reserve(fileSize);
RFile.seekg(0, std::ios::beg);
if (!RFile.read(&fileContent[0], fileSize)) cout << "An error when reading the file." << endl;
RFile.close();
There are no errors appear while compiling or runtime too but there is unknown behavior at runtime/debugging, the program doesn't end and still waiting (something like waiting for inputs).
Is there some wrong in my code?
EDIT
The program finally ended and completed its work, however, I noted:
- The program takes almost 32 seconds to just read 17 MB, is that normal or there is something in my code (I think that is very slow)?
- Also when using
char
data type insteadwchar_t
the reading process became fast as it should be, so, is the problem inwchar_t
data type or what?