error C2065: '_vsntprintf' : undeclared identifier

yatou1990 2011-03-01 05:12:04
这是一个什么问题呢?
我的代码是:

#include <windows.h>
#include <tchar.h>
#include <stdafx.h>
int CDECL MesageBoxPrintf(TCHAR * szCaption,TCHAR * szFormat,...)
{
TCHAR szBuffer[1024];
va_list pArgList;
va_start(pArgList,szFormat);
_vsntprintf(szBuffer,sizeof(szBuffer)/sizeof(TCHAR),szFormat,pArgList);
va_end(pArgList);
return MessageBox(NULL, szBuffer, szCaption, 0);
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
int cxScreen, cyScreen ;
cxScreen = GetSystemMetrics (SM_CXSCREEN) ;
cyScreen = GetSystemMetrics (SM_CYSCREEN) ;
MesageBoxPrintf(TEXT ("ScrnSize"),TEXT ("The screen is %i pixels wide by %i pixels high."),cxScreen, cyScreen);
return 0;
}
但是编译总会出现错误:error C2065: '_vsntprintf' : undeclared identifier
高手们帮我看看是什么错误呢?
...全文
445 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengzhixi 2011-03-01
  • 打赏
  • 举报
回复
如果你的工程选项没有预处理选项就不用将#include <stdafx.h>
放前面了。
yatou1990 2011-03-01
  • 打赏
  • 举报
回复
还是有疑问:
#include <windows.h>
#include <tchar.h>
#include <stdafx.h>
#include <stdio.h>这样的顺序错误就是:error C2065: '_vsntprintf' : undeclared identifier Error executing cl.exe.
而#include <stdafx.h>
#include <stdio.h>
#include <windows.h>
#include <tchar.h>
就行了,
怎么会产生这样的影响呢?
yatou1990 2011-03-01
  • 打赏
  • 举报
回复
谢谢大家,
头文件用成这样就可以了:
#include <stdafx.h>
#include <stdio.h>
#include <windows.h>
#include <tchar.h>
马上结贴
太乙 2011-03-01
  • 打赏
  • 举报
回复
vsnprintf定义在 stdarg.h和stdio.h函数中
太乙 2011-03-01
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20080927/20/391b89e5-38e7-464e-b745-3e4b4d611728.html
yatou1990 2011-03-01
  • 打赏
  • 举报
回复
我转到定义后发现:#define _vsntprintf _vsnprintf
那么_vsntprintf 和_vsnprintf不就是一样的嘛?
yatou1990 2011-03-01
  • 打赏
  • 举报
回复
我的库不包含这个函数,那要怎么解决呢?
yatou1990 2011-03-01
  • 打赏
  • 举报
回复
我在msdn也查过,都只看见了_vsnprintf和_vsnwprintf,为什么没有_vsntprintf呢?
pengzhixi 2011-03-01
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 yatou1990 的回复:]
放在最前面还是不行:error C2065: '_vsnprintf' : undeclared identifier Error executing cl.exe.
[/Quote]

看来你的库不包含这个函数。
yatou1990 2011-03-01
  • 打赏
  • 举报
回复
放在最前面还是不行:error C2065: '_vsnprintf' : undeclared identifier Error executing cl.exe.
赵4老师 2011-03-01
  • 打赏
  • 举报
回复
_vsnprintf, _vsnwprintf
Write formatted output using a pointer to a list of arguments.

int _vsnprintf( char *buffer, size_t count, const char *format, va_list argptr );

int _vsnwprintf( wchar_t *buffer, size_t count, const wchar_t *format, va_list argptr );

Routine Required Header Optional Headers Compatibility
_vsnprintf <stdio.h> and <stdarg.h> <varargs.h>1 Win 95, Win NT
_vsnwprintf <stdio.h> or <wchar.h>, and <stdarg.h> <varargs.h>1 Win 95, Win NT


1 Required for UNIX V compatibility.

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version


Return Value

_vsnprintf and _vsnwprintf return the number of characters written, not including the terminating null character, or a negative value if an output error occurs. For _vsnprintf, if the number of bytes to write exceeds buffer, then count bytes are written and –1 is returned.

Parameters

buffer

Storage location for output

count

Maximum number of characters to write

format

Format specification

argptr

Pointer to list of arguments

Remarks

Each of these functions takes a pointer to an argument list, then formats and writes the given data to the memory pointed to by buffer.

Generic-Text Routine Mappings

TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_vsntprintf _vsnprintf _vsnprintf _vsnwprintf


Stream I/O Routines | vprintf Functions Overview

See Also fprintf, printf, sprintf, va_arg
pengzhixi 2011-03-01
  • 打赏
  • 举报
回复
#include <stdafx.h>
放最前面试试。
yatou1990 2011-03-01
  • 打赏
  • 举报
回复
#include <windows.h>
#include <tchar.h>
#include <stdio.h>

就成了这样子了:fatal error C1010: unexpected end of file while looking for precompiled header directive
Error executing cl.exe.
TimZhuFaith 2011-03-01
  • 打赏
  • 举报
回复
windows 程序设计 源码吧
yatou1990 2011-03-01
  • 打赏
  • 举报
回复
加了是这个效果:
fatal error C1083: Cannot open include file: 'strsafe.h': No such file or directory
Error executing cl.exe.
TimZhuFaith 2011-03-01
  • 打赏
  • 举报
回复
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
jojobhw 2011-03-01
  • 打赏
  • 举报
回复
是这个函数吗_vsntprintf()?没打错吧?
pengzhixi 2011-03-01
  • 打赏
  • 举报
回复
#include <strsafe.h>
好像是这个头文件。
yatou1990 2011-03-01
  • 打赏
  • 举报
回复
#include <windows.h>
#include <tchar.h>
#include <StdAfx.h>
#include <stdio.h>

加了头文件,但是还是那个错误:error C2065: '_vsntprintf' : undeclared identifier
無_1024 2011-03-01
  • 打赏
  • 举报
回复
没有相应的头文件 <stdio.h>
加载更多回复(1)

64,641

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧