c++ 变量小问题

来源:百度知道 编辑:UC知道 时间:2024/06/08 06:41:11
SetWindowText(w,(const char *)argv[3]);

兄弟们知道第2个参数怎么写吗?
这样写运行时说什么什么内存有错

数组 argv 是 char 类型的吧,如果可以用 string ,那么可以通过 string 来返回一个 const char* 的指针:
string s(argv[3]);
const char* ps = s.c_str();
当然,你可以直接 SetWindwosText(w,s.c_str());

如果能用 CString ,那么可以用 CString s("jaycnvip@baidu.com");
const char* p = s.GetBuffer(s.GetLength());
s.ReleaseBuffer();//一定要记得 ReleaseBuffer

以上在VC6,编译通过

CWnd::SetWindowText
void SetWindowText( LPCTSTR lpszString );

Parameters

lpszString

Points to a CString object or null-terminated string to be used as the new title or control text.

Remarks

Sets the window’s title to the specified text. If the window is a control, the text within the control is set.

This function causes aWM_SETTEXT message to be sent to this window.

Example

// set the text in IDC_MYEDIT
CWnd* pWnd = GetDlgItem(IDC_MYEDIT);
pWnd->SetWindowText(_T("Hockey is best!"));

// Get the te