I am trying to read each ‘char’ of the input file and write in the output file until finds the ‘?’ as the end of file . Every char is written in output file except the spaces between words. I dont know what’s wrong in this code??
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream infile("in.txt");
ofstream outfile("out.txt");
char ch;
infile >> ch;
while(ch != '?')
{
outfile<<ch;
infile >> ch;
}
}
Try using noskipws on read…
The noskipws tells the input stream to not skip whitespace which it does by default.