如何将wchar_t(或wchar_t*或CORBA::WChar*)转换为字符串
How to convert wchar_t (or wchar_t* or CORBA::WChar*) to string?
在我的应用程序中,我必须使用CORBA::WChar*(或等效的wchar_t*),但我的程序还需要将一些信息保存到PostgreSQL数据库中。为了在C++中将数据插入PostgreSQL,我使用SOCI。问题在于:
The following types are currently supported for use with into and use expressions:
char (for character values)
short, int, unsigned long, long long, double (for numeric values)
char*, char[], std::string (for string values)
std::tm (for datetime values)
soci::statement (for nested statements and PL/SQL cursors)
soci::blob (for Binary Large OBjects)
soci::row_id (for row identifiers)
所以不支持wchar_t*或wstring...我需要将 CORBA::WChar(或wchar_t或wchar_t*)转换为字符串。怎么做?
我在使用代码块 10.5 时对宽字符(和字符串)也有问题:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
const wchar_t *val = L"ąśżźćłóń";
wcout << val << "n";
return 0;
}
显示:
E:TempUntitled1.cpp||In function 'int main(int, char**)':|
E:TempUntitled1.cpp|7|error: converting to execution character set: Invalid argument|
||=== Build finished: 1 errors, 0 warnings ===|
如何解决?
我还需要代码是可移植的,我可以在 unix/linux 和 Windows 上运行它。
我建议boost::locale::conv::utf_to_utf<char>(wchar_t*)
简单地将wchar_t*
字符串转换为 UTF-8 以获取更多信息,请阅读boost::locale
文档
什么样的数据库不允许存储 Unicode 字符串?我的建议是使用一个像样的数据库。
相关文章:
- 无法将参数 1 从 WCHAR 转换为常量字符 *
- 如何将CString转换为使用WCHAR的Windows API和自定义函数?
- VC++ 2017 如何将常量wchar_t转换为 WCHAR *.
- 将WCHAR转换为LPCTSTR
- 在C++中读取和写入Windows注册表(如何将字符串转换为wchar(?))
- 在 unicode 中将 WCHAR 数组转换为 std::string?
- 将const wchar_t*转换为wchar*
- 将字符从 fget 转换为 Wchar*
- 如何在 iOS 中将 UTF-8 字符串转换为 wchar
- 如何将const char*转换为const WCHAR*
- 如何将wchar_t(或wchar_t*或CORBA::WChar*)转换为字符串
- 如何将strncpy()转换为WCHAR
- 通过COM将C#字符串转换为C++WCHAR*
- 将wchar转换为字符串并推入矢量(C/C++)
- 将 WCHAR[260] 转换为 std::string
- 如何在C++中将WCHAR*转换为字符串,反之亦然
- "strcpy":无法将参数 2 从"WCHAR *"转换为"常量字符 *
- 在Qt中将WCHAR转换为QString
- 如何将WCHAR转换为CString
- C++:将WCHAR转换为LPCWSTR - 实际工作示例