dimanche 4 février 2018

why std::istringstream fail when I set std::locale to "zh_CN.utf8"?

the code is as follow:

#include <iostream>
#include <locale>
#include <sstream>

int main() 
{
std::locale::global(std::locale("zh_CN.UTF-8"));

std::string str = u8"8086";
std::istringstream iss(str);
int e;
iss>>e;
if(iss.fail())
{
    std::cout<<"failed  "<<"e = "<<e<<std::endl;
}

return 0;
}

and the output is:

failed e = 8086

the operator>> is successful but why fail() return true?

Aucun commentaire:

Enregistrer un commentaire