【问题标题】:Showing WideString variable into console在控制台中显示 WideString 变量
【发布时间】:2012-02-22 15:56:23
【问题描述】:

我在控制台中显示 WideString 时遇到问题。一般来说,我对 Builder C++ 和 C++ 完全陌生。不确定我是否需要一些标题或者调试时显示的值可能会有所帮助。好像在做的时候

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

【问题讨论】:

    标签: console-application c++builder cout


    【解决方案1】:

    您正在将 WideString 传递给 wcout。 WideString 是一个完整的类,它包含宽字符并对其进行操作,而不仅仅是字符串。使用 WideString 的c_bstr 方法获取实际字符串。

    WideString str;
    str = L"HELLO";
    wcout << s.b_cstr();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-05
      • 2017-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多