草庐IT

alias_wchar_t

全部标签

c++ - Clang 为使用的类型别名发出 "unused type alias"警告

我有一些代码,Clang正在为其生成警告。这是对实际代码的简化,但精神是一样的。本地类中的this_t用于实例化其他一些模板类。templatestructvalue_holder{Tvalue;};templateintget_value(){structvalue_t{usingthis_t=value_t;//^herestaticvalue_holderval(){returnvalue_holder();}operatorint(){return0;}};returnvalue_t::val().value;}intmain(intargc,char**argv){retur

c++ - 如何将 wchar_t** 转换为 char**?

我得到argv作为wchar_t**(见下文),因为我需要使用unicode,但我需要将它转换为char**。我该怎么做?intwmain(intargc,wchar_t**argv){ 最佳答案 有不止一种方法可以做到这一点。根据您的环境和可用的编译器/标准库/其他库,您至少有三种选择:使用std::locale和std::codecvt方面;使用C语言环境函数,如std::mbstowcs();使用第3方函数,例如*nix上的iconv()或Windows上的WideCharToMultiByte()。您真的需要进行转换吗?您应

c++ - 将 'const wchar_t *' 转换为 'unsigned char *'

在C++中是否可以将'constwchar_t*'转换为'unsignedchar*'?我该怎么做?wstringdirName;unsignedchar*dirNameA=(unsignedchar*)dirName.c_str();//Iamcreatingahashfromastringhmac_sha256_init(hash,(unsignedchar*)dirName.c_str(),(dirName.length)+1); 最佳答案 你需要一个字符一个字符地转换。有像wcstombs这样的函数可以做到这一点。

c++ - 无法将 char* 转换为 WCHAR* [qt/c++]

我正在开发QT应用程序,我需要包含纯C代码。当我在code::blocks中编译这段代码时,它是成功的,可能是一个警告,但是当我尝试在QTcreator中编译它时,我得到了这4个错误。cannotconvert'char*'to'WCHAR*'forargument'1'to'UINTGetSystemDirectoryW(WCHAR*,UINT)'cannotconvert'char*'to'constWCHAR*'forargument'1'to'HINSTANCE__*LoadLibraryW(constWCHAR*)'cannotconvert'char*'to'WCHAR*'

c++ - 从原始内存位置 memcpy 到 vector<wchar_t>

我正在使用一个API,它在内存中提供感兴趣的字符串的内存地址和长度。我想将这些字符串读入更友好的对象,如wstring。对于较小的字符串,静态大小的缓冲区使用以下代码可以正常工作://Thiscodeworks(butmayhaveotherissues)//_stringLengthOffsetand_bufferOffsetareprovidedearlierbytheAPI//stringOIDisthememorylocationofthestring(andintermsoftheAPI,theObjectID)DWORDstringLength;memcpy(&string

c++ - 在 C++ 标准中哪里说 sizeof(wchar_t) <= sizeof(long) 和 sizeof(bool) <= sizeof(long)?

先生。Stroustrup在他的新书(TCPL第4版)第149页写下了以下内容1我在标准中找不到任何支持上面最后一个不等式的内容。我可以对sizeof(bool)说同样的话.编辑:在3.9.1p5你会发现:Typewchar_tshallhavethesamesize,signedness,andalignmentrequirements(3.11)asoneoftheotherintegraltypes,calleditsunderlyingtype.支持不平等sizeof(wchar_t)但不是sizeof(wchar_t)但是我找不到任何可以证实的东西sizeof(bool)

c++将宏变量转换为wchar字符串文字的简单方法

在下面的示例中,我想删除std::wstring(std::widen(...))部分,但是'#'宏只返回一个char字符串文字--有什么方法可以容纳wchar吗?#defineFOO_MACRO(className)\structclassName##Factory:publicOtherClass{\//doessomestuffhere\}className##Factory;\someMap->add(std::wstring(std::widen(#className),className##Factory)))我如何使用wchar做同样的事情?

c++ - 如何为一般情况编写流插入运算符? (也就是说,对于 `char` 和 `wchar_t` 流?)

我正在实现streaminsertionoperator对于我的一个类。我希望我的类(class)能够同时使用窄流和宽流。我正在使用一个模板来允许这种行为——除了字rune字之外,一切都与实际使用的流类型无关。如果它是一个宽字符串,则字rune字需要在文字前面加上L,否则不需要。有没有办法将这种东西键入模板参数,这样我就不需要在上面复制这么多代码?(如果可能,我宁愿避免在运行时执行窄到宽字符或宽到窄字符转换。)我目前拥有的示例——它是一个模板,但由于宽字rune字,它不适用于窄字符流:templatestd::basic_ostream&operator&lhs,constProces

C++:将 L""string 分配给 WCHAR[]?

我有一个WCHAR[]:WCHARfoo[200];我想将值复制到其中:if(condition){foo=L"bar";}else{foo=L"odp";}执行此操作的最佳方法是什么? 最佳答案 wcscpy,尽管最好的办法是使用std::wstring相反。std::wstringfoo;if(condition)foo=L"bar";elsefoo=L"odp";或者如果你坚持使用wcscpy:WCHARfoo[200];if(condition)wcscpy(foo,L"bar");elsewcscpy(foo,L"odp"

c++ - wchar_t 和 char 在 WinDbg 中的表示

注意:/**Trivialcode*/wchar_t*greeting=L"HelloWorld!";char*greeting_="HelloWorld!";WinDbg:0:000>??greetingwchar_t*0x00415810"HelloWorld!"0:000>??greeting_char*0x00415800"HelloWorld!"0:000>db0x004158000041580048656c6c6f20576f-726c642100000000HelloWorld!....00415810480065006c006c00-6f00200057006f00H.