在控制台中显示WideString变量 [英] Showing WideString variable into console

查看:83
本文介绍了在控制台中显示WideString变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在向控制台显示WideString时遇到问题。一般来说,我对Builder C ++和C ++完全陌生。不知道我是否需要一些标头,或者调试时显示的值可能会有所帮助。似乎在进行

I'm having problems showing a WideString into the console. I'm totally new on Builder C++ and C++ in general. Not sure if I need some headers or maybe the values shown when debugging could help. It seems that when doing

wcout << s;

它显示的是地址而不是 wchar数组。

it is showing the address instead of the "wchar array".

这是我的代码:

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


推荐答案

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

You're passing a WideString to wcout. WideString is a whole class that contains and operates on wide characters, not just a string. Use the c_bstr method of WideString to get to the actual character string.

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

这篇关于在控制台中显示WideString变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆