I am facing some issues with non-Ascii chars in C++. I have one file containg non-ascii chars which I am reading in C++ via file Handling. After reading the file(say 1.txt) I am storing the data into string stream and writing it into another file(say 2.txt).
Assume 1.txt contains:
ação
In 2.txt I should get same ouyput but non-Ascii chars are printed as their Hex value in 2.txt.
Also, I am quite sure that C++ is handling Ascii chars as Ascii only.
Please Help on how to print these chars correctly in 2.txt
EDIT:
Firstly Psuedo-Code for Whole Process:
1.Shell script to Read from DB one Value and stores in 11.txt
2.CPP Code(a.cpp) reading 11.txt and Writing to f.txt
Data Present in DB which is being read: Instalação
File 11.txt contains: Instalação
File F.txt Contains: Instalação
Ouput of a.cpp on screen: Instalação
a.cpp
#include <iterator>
#include <iostream>
#include <algorithm>
#include <sstream>
#include<fstream>
#include <iomanip>
using namespace std;
int main()
{
ifstream myReadFile;
ofstream f2;
myReadFile.open("11.txt");
f2.open("f2.txt");
string output;
if (myReadFile.is_open())
{
while (!myReadFile.eof())
{
myReadFile >> output;
//cout<<output;
cout<<"\n";
std::stringstream tempDummyLineItem;
tempDummyLineItem <<output;
cout<<tempDummyLineItem.str();
f2<<tempDummyLineItem.str();
}
}
myReadFile.close();
return 0;
}
Locale says this:
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=