I am having trouble getting my program to read the spaces in my input file, I am new to and objects in general so any help would be appreciated.
My input file is: Hello my name is Pierre. I like to code .
My output file is: HellomynameisPierre.Iliketocode.
Another question I have is how can I check if my string has more than one space, and if it does, replace it with only one space.
#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;
void clean_file(ifstream& fin, ofstream& fout);
int main()
{
ifstream fin;
ofstream fout;
clean_file(fin, fout);
}
void clean_file(ifstream& fin, ofstream& fout)
{
fin.open("string.txt");
if (fin.fail())
{
cout << "File could not open.";
exit(1);
}
fout.open("cleanString.txt");
if (fout.fail())
{
cout << "File could not open.";
exit(1);
}
char line;
while (fin >> line)
{
fout << line;
}
fin.close();
fout.close();
}
Aucun commentaire:
Enregistrer un commentaire