How it’s possible to read characters from file without loosing the spaces?
I have a file which contains for istance this:
The quick brown fox jumps over the lazy dog.
When I read from file (a character a time), I lose the spaces, but the all other characters are correctly read. Why?
This is an example of code:
unsigned int cap = (unsigned)strlen("The quick brown fox jumps over the lazy dog.");
char c[cap];
int i = 0;
while (!fIn.eof()) {
fIn >> c[i];
++i;
}
for (int i = 0; i < cap; i++)
cout << c[i];
When i print the array, all spaces are missing. Could you tell me how I can avoid this problem?
You can use the stream manipulators declared in
<iomanip>.std::noskipwsis the one you want, which instructs stream extraction operators not to skip whitespaces.The other option is to use raw input functions
fstream::get(),fstream::read().