Good day, I am in a small project where I need to read .txt files, the problem is that some are in English and others in Spanish, the case is being presented in which some information comes with an accent and I must show it on the console with the accent.
I have no problem displaying accents on console with setlocale(LC_CTYPE, "C");
my problem is when reading the .txt file in the reading it does not detect the accents and reads rare characters.
my practice code is:
#include <iostream>
#include <locale.h>
#include<fstream>
#include<string>
using namespace std;
int main(){
setlocale (LC_CTYPE, "C");
ifstream file;
string text;
file.open("entryDisciplineESP.txt",ios::in);
if (file.fail()){
cout<<"The file could not be opened."<<endl;
exit(1);
}
while(!file.eof()){
getline(file,text);
cout<<text<<endl;
}
cout<<endl;
system("Pause");
return 0;
}
The .txt file in question contains:
Inicio
D1
Biatlón
S1
255
E1
Esprint 7,5 km (M); 100; 200
E2
Persecucion 10 km (M); 100; 200
ff
obviously I'm having problems with 'ó' but in the same way I have other .txt with other characters with accents so I need a solution for all these characters.
Researching I have read and tried to implement wstring and wifstream but I have not been able to implement that successfully.
I'm trying to achieve this on windows, the same way I need the solution to work on linux, at the moment I'm using dev c++ 5.11
Thank you very much in advance for your time and help.