Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C/C++;从wint\u t打印英镑符号_C++_Unicode_Wchar - Fatal编程技术网

C++ C/C++;从wint\u t打印英镑符号

C++ C/C++;从wint\u t打印英镑符号,c++,unicode,wchar,C++,Unicode,Wchar,我在Linux系统上,将键盘设置为UK,以便捕获并打印英国镑符号(£) 这是我的密码: #include <stdio.h> #include <wchar.h> #include <locale.h> int main () { wint_t wc; fputws (L"Enter text:\n", stdout); setlocale(LC_ALL, ""); do { wc=getwchar(

我在Linux系统上,将键盘设置为UK,以便捕获并打印英国镑符号(£)

这是我的密码:

#include <stdio.h>
#include <wchar.h>
#include <locale.h>

int main ()
{
    wint_t wc;
    fputws (L"Enter text:\n", stdout);

    setlocale(LC_ALL, "");
    do
    {
        wc=getwchar();
        wprintf(L"wc = %lc %d 0x%x\n", wc, wc, wc);
    } while (wc != -1);

    return 0;
}
#包括
#包括
#包括
int main()
{
温特沃克;
fputws(L“输入文本:\n”,标准输出);
setlocale(LC_ALL,“”);
做
{
wc=getwchar();
wprintf(L“wc=%lc%d 0x%x\n”,wc,wc,wc);
}而(wc!=-1);
返回0;
}
另外,我想将英国镑符号(£)存储为字符串的一部分。我发现,当存储宽字符时,std::string并不表示准确的大小……在这种情况下使用wstring更好吗?它提供了更精确的尺寸吗?

您可以使用

#包括
#包括
//包括std::put_money和其他实用程序
#包括
int main(int argc,字符**argv)
{
//价值以美分计!
const int basepay=10000;
std::stringstream-ss;
//设置本地配置
ss.imbue(标准::语言环境(“en_GB.utf8”);

ss在获取输入之前先设置区域设置

#include <stdio.h>
#include <wchar.h>
#include <locale.h>
int main () {
    setlocale(LC_ALL, "en_GB.UTF-8");
    wchar_t wc;
    fputws (L"Enter text:\n", stdout);
    do {
        wc = getwchar();
        wprintf(L"wc = %lc %d 0x%x\n", wc, wc, wc);
    } while (wc != -1);
    return 0;
}
#包括
#包括
#包括
int main(){
setlocale(LC_ALL,“en_GB.UTF-8”);
wchar_t wc;
fputws(L“输入文本:\n”,标准输出);
做{
wc=getwchar();
wprintf(L“wc=%lc%d 0x%x\n”,wc,wc,wc);
}而(wc!=-1);
返回0;
}

我应该重新措辞……我希望它能够打印任何存储在WiTyt中的Unicode符号。谢谢大家的响应。所以我已经有了英国英语的键盘设置,能够显示英国磅符号。只是获取本地用户设置?我不知道。为了得到答案。我不知道C宽字符串和相关函数是如何工作的,但从这个测试中我可以看出,使用宽字符串是你的问题。普通字符工作正常。
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
int main () {
    setlocale(LC_ALL, "en_GB.UTF-8");
    wchar_t wc;
    fputws (L"Enter text:\n", stdout);
    do {
        wc = getwchar();
        wprintf(L"wc = %lc %d 0x%x\n", wc, wc, wc);
    } while (wc != -1);
    return 0;
}