为什么我会收到这样的警告? [英] Why do I get such warning ?
本文介绍了为什么我会收到这样的警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
警告C4477'sprintf':格式字符串'%s'需要类型为'char *'的参数,但可变参数2的类型为'CString'
我尝试了什么:
sprintf(m_Tip.szUnit,%s,用于中继地址);
解决方案
请参阅此处: c ++ - sprintf如何与CString和std :: string一起使用 - Stack Overflow [ ^ ]
Quote:sprintf(m_Tip.szUnit,%s,用于中继地址);
用于中继地址看起来不是
CString
给我。可能你报错了。
顺便问一下,
m_Tip.szUnit = 用于中继地址;
?
尝试使用您的文本的字符数组例如
char s [] = for Relay Address;
sprintf(m_Tip.szUnit, %s,s);或者在这种情况下
m_Tip.szUnit = for Relay Address;
假设
m_Tip.szUnit
定义为std :: string
Warning C4477 'sprintf' : format string '%s' requires an argument of type 'char *', but variadic argument 2 has type 'CString'
What I have tried:
sprintf(m_Tip.szUnit, "%s", "for Relay Address");
解决方案
See here: c++ - How sprintf works with CString and std::string - Stack Overflow[^]
Quote:sprintf(m_Tip.szUnit, "%s", "for Relay Address");
"for Relay Address" doesn't look a
CString
to me. Possibly you are reporting the wrong line.
By the way, what is wrong with
m_Tip.szUnit = "for Relay Address";?
Try using a char array for your text e.g.
char s[] = "for Relay Address"; sprintf(m_Tip.szUnit, "%s", s);Or in this case
m_Tip.szUnit = "for Relay Address";assuming
m_Tip.szUnit
is defined asstd::string
这篇关于为什么我会收到这样的警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文