首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将wchar_t (或wchar_t*或CORBA::WChar*)转换为字符串?

如何将wchar_t (或wchar_t*或CORBA::WChar*)转换为字符串?
EN

Stack Overflow用户
提问于 2012-09-17 05:34:40
回答 2查看 1.3K关注 0票数 0

在我的应用程序中,我必须使用CORBA::WChar* (或等效的wchar_t*),但我的程序还需要将一些信息保存到PostgreSQL数据库中。为了将数据插入到C++中的PostgreSQL,我使用了SOCI。这里有个问题,因为:

代码语言:javascript
复制
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*)转换为字符串。该怎么做呢?

在使用CodeBlocks 10.5时,我也遇到了宽字符(和字符串)的问题:

代码语言:javascript
复制
#include <cstdlib>
#include <iostream>
using namespace std;

int main(int argc, char **argv)
{
    const wchar_t *val = L"ąśżźćłóń";
    wcout << val << "\n";
    return 0;
}

显示:

代码语言:javascript
复制
E:\Temp\Untitled1.cpp||In function 'int main(int, char**)':|
E:\Temp\Untitled1.cpp|7|error: converting to execution character set: Invalid argument|
||=== Build finished: 1 errors, 0 warnings ===|

如何修复它?

我还需要代码是可移植的,我可以在unix/linux和windows上运行它。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-17 05:40:51

我建议boost::locale::conv::utf_to_utf<char>(wchar_t*)简单地将wchar_t*字符串转换为UTF8。有关更多信息,请阅读boost::locale文档

票数 1
EN

Stack Overflow用户

发布于 2012-09-17 05:50:27

哪种数据库不允许您存储Unicode字符串?我的建议是使用一个像样的数据库。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12450920

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档