关于SetWindowText

wushuishui 2010-01-14 11:26:44
const string c="asdfwe";
edit1->SetWindowText(c);出错,为什么不能用string类型呢(前面已经include<string>),非要const char*
...全文
124 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
丨touch 2011-09-16
  • 打赏
  • 举报
回复
CString 和 string 可不是一个类型哦
丨touch 2011-09-16
  • 打赏
  • 举报
回复
    CString	 str1	= "CString";
char *str2 = "Char*";
::SendMessage(g_hWnd, WM_SETTEXT, 0, (LPARAM)str1.GetBuffer());
::SendMessage(g_hWnd, WM_SETTEXT, 0, (LPARAM)str2);

...看懂了么
liumenghappy 2010-01-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 lllyyy2403 的回复:]
SetWindowText的参数要求是CString类型,因此如果你改成
CString c="asdfwe";
edit1->SetWindowText(c);
就不会出错了。
[/Quote]
lllyyy2403 2010-01-14
  • 打赏
  • 举报
回复
SetWindowText的参数要求是CString类型,因此如果你改成
CString c="asdfwe";
edit1->SetWindowText(c);
就不会出错了。
c_s0001 2010-01-14
  • 打赏
  • 举报
回复
类型不一致,当然不能用了
_JeffreyWu 2010-01-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sandyandy 的回复:]
edit1->SetWindowText(c.c_str());
[/Quote]
此人所言极是
zottff 2010-01-14
  • 打赏
  • 举报
回复
晕,这里的string并不是字符串,它是一个模板类,你可以使用CString
sandyandy 2010-01-14
  • 打赏
  • 举报
回复
edit1->SetWindowText(c.c_str());
ripyu 2010-01-14
  • 打赏
  • 举报
回复
ls解释很详细了
luhongyu2108 2010-01-14
  • 打赏
  • 举报
回复

// 把cstring 转换为char * 传入
const cstring c = "asdfwe";
edit1->SetWindowText(c.c_str());


或者直接使用CString
CString c="asdfwe";
edit1->SetWindowText(c);

15,978

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧