2012-02-22 12 views
1

コンソールにWideStringを表示する際に問題があります。私はBuilder C++とC++で全く新しいです。デバッグが助けになるときに、私はいくつかのヘッダーが必要なのか、あるいは値が必要なのかはっきりしていません。WideString変数をコンソールに表示

wcout << s; 

"wchar配列"の代わりにアドレスが表示されているようです。

ここでは、私のコードです:

//--------------------------------------------------------------------------- 
#include <iostream.h> 
#include <vcl.h> 
#include <string> 
#include <wstring.h> 
#pragma hdrstop 
//--------------------------------------------------------------------------- 

#pragma argsused 
int main(int argc, char* argv[]) 
{ 

    int a; 
    WideString s; 
    string str; 

    cout << "Enter a: "; 
    cin >> a; 
    //to read the return 
    cin.get(); 
    cout << "Enter str: "; 
    cin >> str; 
    //to read the return 
    cin.get(); 
    cout << "\n"; 
    s = L"HELLO"; 
    wcout << s; 
    cout << "\n\n"; 
    wcout << L"BYE"; 
    cout << "\n\nPress any key to continue..."; 
    cin.get(); 

    return 0; 

    } 
//--------------------------------------------------------------------------- 

そして、それが出力されます。

Enter a: 4 
Enter str: potato 

2fb0b4 

BYE 

Press any key to continue... 

答えて

3

あなたはwcoutにWideStringのを渡しています。 WideStringは、文字列だけでなくワイド文字を含み、操作するクラス全体です。実際の文字列に到達するには、WideStringのc_bstrメソッドを使用します。

WideString str; 
str = L"HELLO"; 
wcout << s.b_cstr(); 
関連する問題