I think the problem is with your terminal; can you try to run the test code in another terminal? one with known good support for UTF-8?
Output with terminal in UTF-8 mode:
$ ./a.out Success Schrüder
Output with terminal in ISO-8859-15 mode:
$ ./a.out Success SchrÃŒder
Also, please try and run http://sscce.org/ - for posterity, here is your code with everything you need to compile (17676169.cpp):
#include <tinyxml2.h> #include <string> #include <iostream> using namespace std; using namespace tinyxml2; tinyxml2::XMLDocument doc; bool open(string path) { if(doc.LoadFile(path.c_str()) == XML_SUCCESS) return true; return false; } int main() { if(open("Test.xml")) cout << "Success" << endl; XMLNode * node = doc.RootElement(); string test = node->FirstChildElement()->GetText(); cout << test << endl; return 0; }
compiled with:
g++ -o 17676169 17676169.cpp -ltinyxml2
and uuencoded Test.xml - to ensure the use of the same data
begin 660 Test.xml M/#]X; 6P@ =F5R<VEO;CTB,2XP(B!E;F-O9&EN9STB551& +3@B /SX*/&UY6$U, M/@ H@ ("`@/&UY.E185%]55$8X5&5S=
Change 1:
If you want to confirm this theory, run this in eclipse:
#include <iostream> #include <string> #include <fstream> int main() { std::ifstream ifs("Test.xml"); std::string xml_data((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>()); std::cout << xml_data; }
Output with terminal in UTF-8 mode:
$ ./17676169.cat <?xml version="1.0" encoding="UTF-8"?> <myXML> <my:TXT_UTF8Test>Schrüder</my:TXT_UTF8Test> </myXML>
Output with terminal in ISO-8859-15 mode:
$ ./17676169.cat <?xml version="1.0" encoding="UTF-8"?> <myXML> <my:TXT_UTF8Test>SchrÃŒder</my:TXT_UTF8Test> </myXML>