如何修复隐含错误... [英] How do I fix my implicit error...
问题描述
将Visual Studio 2015与VC ++一起使用
char buffer [100];
CString strTmp = _T();
strTmp.Format(_T(%s),缓冲区);不会没有错误信息。
但是在分析了代码之后,它会发出警告invald parameters transit transit ..... etc
以上代码是否有任何危险点?
我尝试过:
几乎我的程序中有从char缓冲区到CString变量的移动值,
我不知道什么是错误。
Using Visual Studio 2015 with VC++
char buffer[100];
CString strTmp = _T("");
strTmp.Format(_T("%s"), buffer); doesn't make no error message.
But after analysing the code, it makes warning "invald parameters transit position.....etc"
Is there any dangerous point of above code?
What I have tried:
In almost of my programs with the moving value from char buffer to CString variable,
I don't know what is error.
推荐答案
这是旧的ANSI和UNICODE问题。
为了避免我使用TCHAR,它将预处理器带入使用正确的char类型。
It is the old ANSI and UNICODE problem.
To avoid I use TCHAR, which brings the preprocessor to use the right char-type.
TCHAR buffer[100];
CString strTmp = _T("");
strTmp.Format(_T("%s"), buffer);
我猜你的编译器在更改后会发现访问缓冲区时出现的一些错误。它是对的:改变它!!!
I guess that your compiler will find after this change some errors in accesing the buffer. And it is right: change that too!!!
除了解决方案1:
如果你需要格式化带有char *
字符串参数的字符串,您可以使用h
前缀在格式中指定此字符:
In addition to solution 1:
If you need to format a string with achar*
string argument, you can specify this in the format by using theh
prefix:
char buffer[100] = "A char* string";
CString strTmp;
strTmp.Format(_T("%hs"), buffer)
这将转换 char *
在运行时将字符串转换为宽字符串,并使用Unicode构建插入该字符串。对于非Unicode构建,前缀将被忽略。
This will convert the char*
string to a wide string during runtime and insert that with Unicode builds. With non-Unicode builds the prefix is ignored.
这篇关于如何修复隐含错误...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!