Ich versuche, mit der Nutzung der locale Facetten wstring zu Zeichenfolge zu konvertieren, aber ich habe auf folgenden Fehler fest:'virtuelle char std :: ctype <wchar_t> :: do_narrow (wchar_t, char) const' geschützt ist
test_facet.cpp: In function ‘int main()’:
test_facet.cpp:14: error: invalid initialization of reference of type ‘std::ctype<wchar_t>&’ from expression of type ‘const std::ctype<wchar_t>’
/usr/include/c++/4.4/bits/locale_facets.h:1430: error: ‘virtual char std::ctype<wchar_t>::do_narrow(wchar_t, char) const’ is protected
test_facet.cpp:16: error: within this context
Quelle:
#include <iostream>
#include <string>
#include <locale>
#include <algorithm>
using namespace std;
int main()
{
locale loc("");
std::wstring Str = L"ěščřžýáíé";
std::string Str2;
ctype<wchar_t> &ct = std::use_facet<std::ctype<wchar_t> >(loc);
for(std::wstring::const_iterator It = Str.begin(); It < Str.end(); ++It)
ct.do_narrow(*It, 'X');
std::cout << Str2 <<std::endl;
}
mir jemand sagen könnte, was ich falsch bin dooing?
Dank
danke für die antwort, irgendwie habe ich alle öffentlichen mitglieder von ctype vermisst und schaute nur auf die geschützten :(albern mich – Trakhan