简体   繁体   English

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

[英]How to convert wchar_t (or wchar_t* or CORBA::WChar*) to string?

In my app I have to use CORBA::WChar* (or equivalent wchar_t*) but my program also needs to save some information to the PostgreSQL database. 在我的应用程序中,我必须使用CORBA :: WChar *(或等效的wchar_t *),但是我的程序还需要将一些信息保存到PostgreSQL数据库中。 To insert data to PostgreSQL in C++ I use SOCI. 要将数据插入C ++中的PostgreSQL,我使用SOCI。 And there's the problem because : 还有问题是因为:

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)

so theres no wchar_t* or wstring supported ... and I need to convert CORBA::WChar (or wchar_t or wchar_t*) to string. 因此不支持wchar_t *或wstring ...,我需要将CORBA :: WChar(或wchar_t或wchar_t *)转换为字符串。 How to do this? 这个怎么做?

I also have problem with wide chars (and strings), using CodeBlocks 10.5 : 使用CodeBlocks 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;
}

shows: 显示:

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 ===|

how to fix it? 如何解决?

I also need the code to be portable, that I can run it both on unix/linux and windows. 我还需要可移植的代码,以便可以在unix / linux和Windows上运行它。

我建议使用boost::locale::conv::utf_to_utf<char>(wchar_t*)wchar_t*字符串转换为UTF-8以获得更多信息,请阅读boost::locale文档

What kind of database doesn't let you store Unicode strings? 哪种数据库不让您存储Unicode字符串? My suggestion would be to use a decent database. 我的建议是使用一个不错的数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM