0

私のアプリでは、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 *)を文字列に変換する必要があります。これを行う方法?

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;
}

ショー:

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の両方で実行できるように、コードを移植可能にする必要があります。

4

2 に答える 2

1

boost::locale::conv::utf_to_utf<char>(wchar_t*)詳細については、文字列を UTF-8 に変換することをお勧めします。ドキュメントをおwchar_t*読みください。boost::locale

于 2012-09-16T21:40:50.617 に答える
-1

Unicode文字列を保存できないのはどのようなデータベースですか?私の提案は、まともなデータベースを使用することです。

于 2012-09-16T21:50:26.787 に答える