I have a problem reading a txt file and getting it out of the console. I need to use Spanish letters. The txt file is encoded in "utf-8 with BOM"
This is text of the texInput.txt file:
Hello. Look how it shows the letter " ñ ",
and the letters with tilde: "á é í or ú"
I want to process texts in Spanish.
Please help.
Here the main.cpp code:
#include <fstream>
#include <iostream>
#include <string>
#include <locale.h>
using namespace std;
wstring inputStr;
wchar_t wc;
wifstream te;
void openTxt();
void readTxt();
void closeTxt();
void wait();
int main(){
setlocale(LC_ALL,"Spanish");
openTxt();
readTxt();
closeTxt();
wait();
return 0;
}
void openTxt(){
te.open("texInput.txt",ios::in);
if (te.fail()){
cout<<"No se pudo abrir el archivo de texto";
exit(1);
}
}
void readTxt(){
while(te.good()){
te.get(wc);
inputStr.push_back(wc);
}
wcout<<inputStr<<endl;
}
void closeTxt(){
te.close();
}
void wait(){
wcout<<L"type something to exit: "<<endl;
wcin>>wc;
}
This is what it looks like on the console:
Hello. Look how it shows the letter " ñ ",
and the letters with tilde: "á é à or ú"
I want to process texts in Spanish.
Please help.
type something to exit: