gpt4 book ai didi

c++ - CString 对象总是返回指针值

转载 作者:行者123 更新时间:2023-11-28 00:05:10 25 4
gpt4 key购买 nike

在visual studio 2015环境下,我只是做了一个简单的Win32控制台应用程序项目来学习MFC。 (另外,我检查了在项目向导过程中添加MFC的公共(public)头文件)

这是这个项目的主要部分..

#include "stdafx.h"
#include "Practice02.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

CWinApp theApp;

using namespace std;

int main()
{
int nRetCode = 0;

HMODULE hModule = ::GetModuleHandle(nullptr);

if (hModule != nullptr)
{
if (!AfxWinInit(hModule, nullptr, ::GetCommandLine(), 0))
{
wprintf(L"error: sample\n");
nRetCode = 1;
}
else
{
CString temp(L"Hello");
cout << temp << endl;
}
}
else
{
wprintf(L"Fatal Error: GetModuleHandle failure\n");
nRetCode = 1;
}

return nRetCode;
}

我的目的是制作一个简单的程序,在 cmd 屏幕上打印包含“hello”值的 CString 对象。

但是,在启动这个项目之后,我只看到了这个对象的地址值。(例如 0039841 或 003913E1 等...)

我应该在哪里修改此代码以打印 CString 对象的实际值?

最佳答案

使用以下内容:

std::wcout << temp.GetString();

关于c++ - CString 对象总是返回指针值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36125078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com