int转换成CString出错

开发环境VS2005
tempratureall[]为一个整数数组且已经赋值
CDC *pDC=GetDC();
CString s;
s.Format("%d", tempratureall[1]);
pDC->TextOut(20,39,s);

总是提示出错
error C2664: “void ATL::CStringT <BaseType,StringTraits>::Format(const wchar_t *,...)”: 不能将参数 1 从“const char [3]”转换为“const wchar_t *”

网友回复:itoa
网友回复:s.Format( _T("%d"), tempratureall[1]);

网友回复:用itoa也试过了也不行
itoa(tempratureall[1],&s,10);
网友回复:s.Format(_T("%d"), tempratureall[1]);
////////////////////////////////////////////////////////////////////////////////////////////////
我建立了以个简单的MFC框架,然后在
void CMy1View::OnDraw(CDC* pDC)
函数中插入了如下的代码
CString strOutput;
strOutput.Format("%s","Hello World!");
pDC -> TextOut(0,0,strOutput);

为什么编译的时候出现了
错误 1 error C2664: “void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)”: 不能将参数 1 从“const char [3]”转换为“const wchar_t *”
这个错误??
很不理解,书上也是这么写的。。。我初学,真不知道怎么办了。

如果就加
pDC -> TextOut(0,0,"Hello World!");
也出现错误
错误 1 error C2664: “BOOL CDC::TextOutW(int,int,const CString &)”: 不能将参数 3 从“const char [13]”转换为“const CString &”
为什么呢?
////////
最佳答案
你在头文件里包含#include <tchar.h>
然后这样初始化
strOutput.Format(_T("%s"),_T("Hello World!"));
因为默认情况下,字符串都是unicode的形式,
用unicode在nt以上的系统是一个很好的方式 

posted on 2010-01-14 10:18 wrh 阅读(2518) 评论(2)  编辑 收藏 引用

评论

# re: int转换成CString出错 2010-01-14 12:24 陈梓瀚(vczh)

itow之后就可以拿到wchar_t*了,然后构造CString。比这个要方便得多。  回复  更多评论   

# re: int转换成CString出错 2010-03-23 17:03 地方

在项目菜单里,你命名的属性改字符编码。使用的是unicode改成多字符型就ok了  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


导航

<2010年2月>
31123456
78910111213
14151617181920
21222324252627
28123456
78910111213

统计

常用链接

留言簿(19)

随笔档案

文章档案

收藏夹

搜索

最新评论

阅读排行榜

评论排行榜