vs编译错误
error C2665: 'swprintf' : none of the 2 overloads could convert all the argument types
代码是:
TCHAR tcsCom[10];
swprintf( tcsCom, _T("COM%d"), 1);
[解决办法]
改用:_stprintf
_stprintf( tcsCom, _T("COM%d"), 1);
[解决办法]
记得:
#include <tchar.h>
[解决办法]
When you use sprintf(), the first argument is a buffer that you're printing to. The same is the case for swprintf(), except the buffer is of wchar_t instead of char.
wchar_t buffer[SOME_NUMBER];
swprintf(buffer, "format string", args);
意思说你那个tcsCom应该是wchar_t型
参看
http://www.gamedev.net/community/forums/topic.asp?topic_id=473673&whichpage=1�
[解决办法]
原因是重载的函数 每个参数都不符合 你提供的
你可以F12去看一下申明
[解决办法]
- C/C++ code
#include <stdio.h>int main( void ){ char buffer[200], s[] = "computer", c = 'l'; int i = 35, j; float fp = 1.7320534f; // Format and print various data: j = sprintf( buffer, " String: %s\n", s ); // C4996 j += sprintf( buffer + j, " Character: %c\n", c ); // C4996 j += sprintf( buffer + j, " Integer: %d\n", i ); // C4996 j += sprintf( buffer + j, " Real: %f\n", fp );// C4996 // Note: sprintf is deprecated; consider using sprintf_s instead printf( "Output:\n%s\ncharacter count = %d\n", buffer, j );}