cuốn sách gpt4 ai đã làm

c++ - 是否可以将引号 („) 放入 Char

In lại Tác giả: Walker 123 更新时间:2023-11-28 01:21:10 30 4
mua khóa gpt4 Nike

tôi đang cố gắng push_back()一个 std::vector 的符号.

我一直收到错误:

character too large for enclosing character literal type

void CharVect (std::vector&temp)
{
temp.push_back('-');
temp.push_back(',');
temp.push_back('.');
temp.push_back('?');
temp.push_back('!');
temp.push_back(':');
temp.push_back(';');
temp.push_back('(');
temp.push_back(')');
temp.push_back('„'); // error
temp.push_back('”'); // error, but " works
temp.push_back('{');
temp.push_back('}');
temp.push_back('*');
temp.push_back('#');
}

câu trả lời hay nhất

sử dụngwchar_t:

#include 

void CharVect(std::vector &temp)
{
temp.push_back(L'-');
temp.push_back(L',');
temp.push_back(L'.');
temp.push_back(L'?');
temp.push_back(L'!');
temp.push_back(L':');
temp.push_back(L';');
temp.push_back(L'(');
temp.push_back(L')');
temp.push_back(L'„'); // works
temp.push_back(L'”'); // works
temp.push_back(L'{');
temp.push_back(L'}');
temp.push_back(L'*');
temp.push_back(L'#');
}

Live Demo

或者您可以考虑使用 std::wstring 来存储宽字符。

BẰNGGem Taylor points out ,如果您需要处理扩展的表情符号,您可能需要考虑使用 wchar32_t.

关于c++ - 是否可以将引号 („) 放入 Char,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56225788/

30 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress