
我用VC++2008写的用FORMAT 格式化字符串怎么不对呢?
我建立了以个简单的MFC框架,然后在voidCMy1View::OnDraw(CDC*pDC)函数中插入了如下的代码CStringstrOutput;strOutput....
我建立了以个简单的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 &”
为什么呢? 展开
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 &”
为什么呢? 展开
3个回答
展开全部
CString strOutput;
strOutput.Format("%s","Hello World!");
pDC -> TextOut(0,0,strOutput);
修改为
CString strOutput;
strOutput.Format("%s",L"Hello World!");
pDC -> TextOut(0,0,strOutput);
因为VS里用的是Unicode编码,所以字符串要改为宽字符。在字符串前加个L
strOutput.Format("%s","Hello World!");
pDC -> TextOut(0,0,strOutput);
修改为
CString strOutput;
strOutput.Format("%s",L"Hello World!");
pDC -> TextOut(0,0,strOutput);
因为VS里用的是Unicode编码,所以字符串要改为宽字符。在字符串前加个L
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你在头文件里包含#include <tchar.h>
然后这样初始化
strOutput.Format(_T("%s"),_T("Hello World!"));
因为默认情况下,字符串都是unicode的形式,
用unicode在nt以上的系统是一个很好的方式
然后这样初始化
strOutput.Format(_T("%s"),_T("Hello World!"));
因为默认情况下,字符串都是unicode的形式,
用unicode在nt以上的系统是一个很好的方式
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
信春哥说的对,08默认是宽字符
写成strOutput.Format(_T("%s"),_T("Hello World!"));
写成strOutput.Format(_T("%s"),_T("Hello World!"));
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询