I have an input text file of 4 lines, each line is 80 characters fixed length. I want to replace every comma by a space. I have written code shown as follows and compiled and run in Code::Blocks IDE. The problem is that the output file contains an extra line.Kindly help me correct the mistake. I'm a beginner in C++.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream in("circArc.txt", ios::in | ios::binary);
if(!in)
{
cout << "Cannot open file";
return 1;
}
ofstream out("readInt.txt", ios::out | ios::binary);
if(!out)
{
cout << "Cannot open file";
return 1;
}
string str;
char rep[80]; //replace array
while(in)
{
getline(in,str);
for(int i=0; i<80; i++)
{
if(str[i] == ',')
rep[i] = ' ';
else
rep[i] = str[i];
out.put(rep[i]);
}
out << endl;
}
in.close();
out.close();
return 0;
}