- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我目前正在 Windows 上开发,但我想稍后让我的应用程序跨平台。它没有/不需要 GUI。
我一直在使用 wstrings,希望这是最好的解决方案。我在项目设置中使用“多字节字符集”。
所有其他平台也支持 wstring 吗?
最佳答案
即使std::wstring
受其他平台支持,其定义和含义似乎因平台而异:例如wchar_t
(这是 std::wstring
的基本“构建 block ”) is 2 bytes in size on Windows, while on on Linux it's 4 bytes .
因此,您可以使用 std::wstring
在 Windows 上以 UTF-16 格式存储 Unicode 字符串(这也是 Win32 API 使用的 Unicode 格式),但在 Linux 上您的 std::wstring
应该用于存储 Unicode UTF-32 字符串。因此,如果同一个类 ( std::wstring
) 在不同平台上有不同的含义,我不会将其定义为可移植的。
如果您想编写可移植代码,您可以考虑使用 std::string
并在其中存储 Unicode UTF-8 文本(事实上,std::string
是基于 char
的,它在 Windows 和 Linux 上都是 1 个字节)。
或者,如果您可以使用新的 C++11 标准,您可能需要考虑 std::u16string
,它非常便携,因为它被定义为 basic_string<char16_t>
, 因此它可以用于在每个平台上存储 Unicode UTF-16 文本,而不会产生歧义。
关于C++:wstring 是跨平台的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15986810/
我想像下面的 c++ 代码一样使用 std::wstring 类型编写 ChaiScript 代码。 #include int testfunc(std::wstring s, std::wstri
以下是我尝试过的,但没有成功。 std::wstring = L"Text"; USES_CONVERSION; LPOLESTR lpDesc = W2OLE((LPWSTR)wsDescr.c_s
我有一个 map . 我插入了这样的对: m_Translations.Content().insert(pair(L"rome",L"roma")); m_Translations.Content(
我正在使用 std::string 作为文本缓冲区。然后,我确定该缓冲区中包含的数据是 UTF-16(即它实际上是一个 std::wstring)。 如何将 std::string 强制转换为 std
摘录如下: ... std::vector vecWstr; vecWstr.emplace_back(L"1"); wchar_t* data1 = vecWstr[0].data(); //在一个
我知道这应该很容易,但我就是没能消除编译错误。这是我的代码: template struct basic_field_type_map : public hash_map, basic_string>
我在 C++ 中有一个 wstring 变量和一个字符串变量。我想将它们连接起来,但简单地将它们相加会产生构建错误。我怎样才能将它们结合起来?如果我需要将 wstring 变量转换为字符串,我该如何完
我有一个简单的记录器类,我试图将其变成接受和输出 wstrings 而不是字符串。 标题: #include using namespace std; class CLog { public:
我的问题是,以前用于字符串的方法都不能用于 wstring。所以我问我如何才能轻松清除 wstring 以达到美学目的。 我现在的代码: while (!foundRightOne)
我已经尝试使用 wchar_t 和一个 for 循环来通过 wchar 读取内存 wchar 并且它有效。工作代码: int cl = 20; std::wstring wstr; wchar_t L
我正在尝试将一个整数附加到 wstring: TCHAR buffer[MAX_PATH]={0}; GetModuleFileName(NULL, buffer, sizeof(buffer)/si
我定义了这样一个枚举: enum eFeature { eF_NONE=0, eF_PORT_A=1, eF_PORT_B=2, eF_PORT_C=3, }; 我现在
我想简化代码以对 ANSI 和 UNICODE 字符串版本使用相同的函数 tstring formatW(const std::string format, ...); tstring formatA
如果我想要像下面这样的函数在 basic_string 上工作和 basic_string我应该怎么办?请注意,它必须更改 wchar_t在无序映射中。 函数还需要接受wchar_t数组以支持将参数作
我有一个 wstring 变量,我想按空格字符拆分它并放入一个 vector wstring wStr = L"Hello World !"; vector vw; wstring st = L"";
我想定义一个 union 体,用于读取特殊类型的二进制文件。 union 应该有两个成员,一个是 int,另一个是一种字符串,或者任何其他的问题;执行此操作的最佳方法是什么? union uu {
目前,我正在为一位中国客户开发一款应用。中国客户大多在其操作系统编码中切换到 GB2312 语言。我需要编写一个文本文件,它将使用 GB2312 进行编码。 我使用std::ofstream 文件 我
在我的程序中,我使用 wstring 打印出我需要的文本,但它给了我随 secret 码(由于不同的编码方案)。例如,我有这段代码。 wstring text; text.append(L"Some
我是 C++ 新手,遇到了这个问题。我有一个名为 DATA_DIR 的字符串,我需要将其格式化为 wstring。 string str = DATA_DIR; std::wstring temp(L
我有一个包含文本的 std::wstring 变量,我需要用分隔符将它拆分。我怎么能这样做?我不会使用会产生一些警告的 boost。谢谢 编辑 1这是一个示例文本: hi how are you? 这
我是一名优秀的程序员,十分优秀!