dimanche 29 mars 2015


This is a link to my previous question with some code that I have.


Thanks.


Here is the code I have so far.



#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.get(line))
{
fout << line;
}


fin.close();
fout.close();
}


The input file I currently have has extra spaces between some of the words and I want to figure out how to check if the string has more than one space and if it does, to replace it with one space. I am thinking I have to check each character by itself and if the consecutive characters are both spaces then I need to replace it with only one. I have searched my question online but I can't find out how to do it by only using the libraries I mentioned before.




Aucun commentaire:

Enregistrer un commentaire