mercredi 19 septembre 2018

Totally confused about reading UTF8 file under linux

I want to read linux UTF8 file char by char. I wanted to use wifstream:

std::wifstream wi("file");
wi.imbue(std::locale(std::locale(""), new std::codecvt_utf8<wchar_t>));

And read it with wchar_t:

for(wchar_t c; wi.get(c);) {
    std::wcout << c;
}

But after reading this: char vs wchar_t vs char16_t vs char32_t (c++11) I'm totaly confused.

  • What should I use char, char16_t, char32_t
  • Should I use ifstream or wifstream
  • Should I use new std::codecvt_utf8
  • How I can extract single 'character' from file

My goal is to read file 'char' by 'char' and put each 'characted' to vector:

'vector<?>':
std::vector<?> chars;
for(? c; wi.get(c);) {
     chars.push_back(c);
}

Thanks

Aucun commentaire:

Enregistrer un commentaire