hello everyone, what this program is supposed to do is to get text from a file and remove all weird characters (1234567890!@$#%^&*) and then output the cleaned text to the same file (cleaning it). for example if a file had the text
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
int main()
{
string filename = "C:\\Users\\Matt\\Desktop\\c++ text files\\info.txt";
fstream myFile;
//getline(cin,filename);
myFile.open(filename);
if(myFile.fail())
{
cout<<"fail";
exit(1);
}
string text;
while(!myFile.eof())
{
myFile >> text;
int s = text.length();
int pos = 0;
//cout << s << endl;
//cout << text << endl;
for (int i = 0; i < s; i++)
{
char check = text.at(pos);
//cout << check << endl;
//cout << i << endl;
int num = (int) check;
//cout << num << endl;
if (num > 90 && num < 97)
{
text.erase(pos,1);
}
check = text.at(pos);
num = (int) check;
if (num > 64 && num < 123 )
{
pos++;
}
else
{
text.erase(pos,1);
}
}
cout << text << " ";
ofstream file2;
file2.open(filename);
file2 << text << endl;
}
myFile.close();
//exit(1);
return 0;
}
there are 2 problems with this program i cant figure out
1. if i flood the file with enough characters (not sure if letters or special characters causes it) i start getting a ton of errors while the program runs, whats weird is if i keep clicking continue on the errors the text will still get cleaned correctly
2. my second problem is getting the clean text to output correctly to the file, my algorithm for cleaning seems to work fine but i cant figure out how to correctly write the cleaned text to the file without messing it up.