在控制台中显示WideString时出现问题。一般来说,我对Builder C++和C++都是新手。不确定我是否需要一些头文件,或者调试时显示的值是否有用。看起来在做的时候
wcout << s;它显示的是地址,而不是"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...发布于 2012-02-23 01:21:53
您正在向wcout传递一个WideString。WideString是一个完整的类,它包含并操作宽字符,而不仅仅是字符串。使用WideString的c_bstr方法获取实际的字符串。
WideString str;
str = L"HELLO";
wcout << s.b_cstr();https://stackoverflow.com/questions/9398269
复制相似问题