Answer the question
In order to leave comments, you need to log in
Why doesn't wstring::c_str() display the Russian part of the text?
The problem is that:
there is a string str - contains a part in English, a part in Russian.
I create wstring strW(str.begin(), str.end());
If you try to output .c_str():
wcout << strW.c_str() ;
Then only the English part is displayed (moreover, wstring::length() - says that the string is correct - uncut length like str)
Tried:
wcin.imbue(locale("rus_rus.866"));
wcout.imbue(locale("rus_rus.866"));
But it:
1 - doesn't work (if only looping to display strW character-by-character - it displays the whole line)
2 - I need it for:
hf = FindFirstFile(strW.c_str(), &fd);
not for wcout
Answer the question
In order to leave comments, you need to log in
Isn't 866 encoding just for the console?
Any functions must accept either unicode or, if it's WinAPI legacy, 1251.
imbue() applies the locale for I/O operations, such as how to display the fraction separator: dot or comma. At the beginning, before I / O operations, you need to put:
std::locale system("");
std::locale::global(system);
#include <iostream>
#include <locale>
using namespace std;
int main()
{
std::locale system("");
std::locale::global(system);
wstring str = L"hello, world. привет, МКС";
wcout << str << endl;
wcout << str.c_str() << endl;
wcout << 3.14 << endl;
// А теперь будет десятичный разделитель согласно локали выводится
wcout.imbue(system);
wcout << 3.14 << endl;
return 0;
}
hello, world. привет, МКС
hello, world. привет, МКС
3.14
3,14
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question