The file being read is ignoring spaces

Hi
I am new to C++
I am trying to read a file and display the contents.
I am using the following code

inFile.open(name);

while(inFile)
{
// Displaying the original text
inFile >> text;
cout << text ;
}
inFile.clear();
inFile.close();

Here, If i am having the text as 'Hi good morning' It is getting displayed as 'Higoodmorning'.

Thanks for the help

Try using getline() into a string instead of the extraction operators. The extraction operators stop at whitespace and will ignore any leading whitespace they find, IIRC.
I actually need to use the << operator.. Is there any other way other than getline().. and also I need to manipulate all the characters in the file by adding 5 to the ascii values of each character and print them ... So I wanted to copy the whole file into another file. Is there a way?

ThanQ soo much
You can tell the stream to not skip whitespace with the noskipws stream manipulator, I suppose.
http://cplusplus.com/reference/iostream/manipulators/noskipws/
I actually need to use the << operator..


Why?
Topic archived. No new replies allowed.