I am trying to replace characters badSymbols to goodSymbols in my text file, but it adds one more character to my replacing character. For example, when I replace 'æ' with 'c', I get 'Ãc'.
This simple program reads text file line by line and replaces characters, then writes it in "fileout.txt"
int main() { char buffer, c; string line, filepath; fstream filein, fileout; char badSymbols[] = {'', 'ê', '³', 'æ', '', '¹', '¿', '£', '', '³', ''}; char goodSymbols[] = {'s', 'e', 'l', 'c', 'z', 'a', 'z', 'L', 's', 'l', ''}; string symbol; size_t found; cout << "Podaj sciezke pliku, w którym zamienic znaki" << endl; cin >> filepath; filepath = filepath + ".txt"; filein.open("/home/damian/jezykc++/untitled2/gared.txt", ios:: in ); fileout.open("/home/damian/jezykc++/untitled2/fileout.txt", ios::trunc | ios::out); if (filein.good() == true) { std::cout << "Uzyskano dostep do pliku!" << std::endl; while (getline(filein, line)) { // buffer=line; //getline(filein,line); for (int i = 0; i < sizeof(badSymbols); i++) { symbol = goodSymbols[i]; found = line.find(badSymbols[i]); if (found != std::string::npos) line.replace(found, 1, symbol); } cout << line << endl; fileout << line << endl; } } else std::cout << "Dostep do pliku zostal zabroniony!" << std::endl; return 0; }