读书人

MSDN和库的头文件里的说明不一致?该怎

发布时间: 2012-03-29 12:53:12 作者: rapoo

MSDN和库的头文件里的说明不一致?
今天调用rename这个函数的时候,发现一件很有意思的事情啊。
这个是rename 在 wchar.h里的声明。
_CRTIMP __checkReturn int __cdecl _wrename(__in_z const wchar_t * _NewFilename, __in_z const wchar_t * _OldFilename);
然后是MSDN的说明int _wrename(
const wchar_t *oldname,
const wchar_t *newname
);
开始我是直接看的头文件里的说明的。。。。紧着着用着不对头,去网上查了下,发现了问题,然后查询MSDN。。。
难道是我哪儿理解错了么?欢迎讨论呀。分数分呀分。

[解决办法]
按照MSDN来。头文件里面只是_wrename,不是rename。说不定在调用rename的时候将参数互换下再调用_wrename了。
[解决办法]
_wrename是rename的宽字符版。

rename, _wrename
Rename a file or directory.

int rename(
const char *oldname,
const char *newname
);
int _wrename(
const wchar_t *oldname,
const wchar_t *newname
);
Parameters
oldname
Pointer to old name.

newname
Pointer to new name.

Return Value
Each of these functions returns 0 if it is successful. On an error, the function returns a nonzero value and sets errno to one of the following values:

EACCES
File or directory specified by newname already exists or could not be created (invalid path); or oldname is a directory and newname specifies a different path.

ENOENT
File or path specified by oldname not found.

EINVAL
Name contains invalid characters.

For other possible return values, see _doserrno, _errno, syserrlist, and _sys_nerr.

Remarks
The rename function renames the file or directory specified by oldname to the name given by newname. The old name must be the path of an existing file or directory. The new name must not be the name of an existing file or directory. You can use rename to move a file from one directory or device to another by giving a different path in the newname argument. However, you cannot use rename to move a directory. Directories can be renamed, but not moved.

_wrename is a wide-character version of _rename; the arguments to _wrename are wide-character strings. _wrename and _rename behave identically otherwise.

Generic-Text Routine Mappings
TCHAR.H routine
_UNICODE & _MBCS not defined
_MBCS defined
_UNICODE defined
_trename
rename
rename
_wrename
Requirements
Routine
Required header
rename
<io.h> or <stdio.h>
_wrename
<stdio.h> or <wchar.h>
For additional compatibility information, see Compatibility in the Introduction.

Libraries
All versions of the C run-time libraries.

Example
// crt_renamer.c
/* This program attempts to rename a file named
* CRT_RENAMER.OBJ to CRT_RENAMER.JBO. For this operation
* to succeed, a file named CRT_RENAMER.OBJ must exist and
* a file named CRT_RENAMER.JBO must not exist.
*/

#include <stdio.h>

int main( void )
{
int result;
char old[] = "CRT_RENAMER.OBJ", new[] = "CRT_RENAMER.JBO";

/* Attempt to rename file: */
result = rename( old, new );
if( result != 0 )
printf( "Could not rename '%s'\n", old );
else
printf( "File '%s' renamed to '%s'\n", old, new );
}
Output
File 'CRT_RENAMER.OBJ' renamed to 'CRT_RENAMER.JBO'
.NET Framework Equivalent
System::IO::File::Move

See Also
Reference
File Handling
[解决办法]
__cdecl _wrename(__in_z const wchar_t * _NewFilename, __in_z const wchar_t * _OldFilename);


int _wrename(
const wchar_t *oldname,
const wchar_t *newname
);
这两个是完全一致的,去掉调用约定附加的东西就是一样
[解决办法]
使用官方的在线文档吧,我就是使用这个的很好。www.cplusplus.com/reference/
[解决办法]
这能有什么误导?!

我第一次发现实际文件中的声明写法可以有这么多枝枝节节,不像“说明书”上写得那么简练时,只是觉得有点吃惊 :)
[解决办法]

C/C++ code
File: "C:\60G\Microsoft SDK\Include\Win64\crt\wchar.h" 1 occurrences found on 1 lines   294: _CRTIMP int __cdecl _wrename(const wchar_t *, const wchar_t *);File: "C:\60G\Microsoft SDK\src\crt\wchar.h" 1 occurrences found on 1 lines   329: _CRTIMP int __cdecl _wrename(const wchar_t *, const wchar_t *);File: C:\MSVC20\INCLUDE\WCHAR.H 1 occurrences found on 1 lines   270: _CRTIMP int __cdecl _wrename(const wchar_t *, const wchar_t *);File: "C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\crt\wchar.h" 1 occurrences found on 1 lines   295: _CRTIMP int __cdecl _wrename(const wchar_t *, const wchar_t *);File: "C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\src\crt\wchar.h" 1 occurrences found on 1 lines   329: _CRTIMP int __cdecl _wrename(const wchar_t *, const wchar_t *);File: "C:\Program Files\Microsoft Visual Studio\VC98\CRT\SRC\WCHAR.H" 1 occurrences found on 1 lines   295: _CRTIMP int __cdecl _wrename(const wchar_t *, const wchar_t *);File: "C:\Program Files\Microsoft Visual Studio\VC98\Include\WCHAR.H" 1 occurrences found on 1 lines   264: _CRTIMP int __cdecl _wrename(const wchar_t *, const wchar_t *);File: "C:\Program Files\Microsoft Visual Studio 10.0\VC\crt\src\wchar.h" 1 occurrences found on 1 lines   336: _Check_return_ _CRTIMP int __cdecl _wrename(_In_z_ const wchar_t * _OldFilename, _In_z_ const wchar_t * _NewFilename);File: "C:\Program Files\Microsoft Visual Studio 10.0\VC\include\wchar.h" 1 occurrences found on 1 lines   312: _Check_return_ _CRTIMP int __cdecl _wrename(_In_z_ const wchar_t * _OldFilename, _In_z_ const wchar_t * _NewFilename);File: "C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\wchar.h" 1 occurrences found on 1 lines   345: _CRTIMP __checkReturn int __cdecl _wrename(__in_z const wchar_t * _NewFilename, __in_z const wchar_t * _OldFilename);File: "C:\Program Files\Microsoft Visual Studio 8\VC\include\wchar.h" 1 occurrences found on 1 lines   321: _CRTIMP __checkReturn int __cdecl _wrename(__in_z const wchar_t * _NewFilename, __in_z const wchar_t * _OldFilename);File: C:\Win2000DDK\inc\wchar.h 1 occurrences found on 1 lines   280: _CRTIMP int __cdecl _wrename(const wchar_t *, const wchar_t *);
[解决办法]
探讨

C/C++ code
File: "C:\60G\Microsoft SDK\Include\Win64\crt\wchar.h" 1 occurrences found on 1 lines
294: _CRTIMP int __cdecl _wrename(const wchar_t *, const wchar_t *);
File: "C:\60G\Microsoft SDK\s……

[解决办法]
探讨
引用:

C/C++ code
File: "C:\60G\Microsoft SDK\Include\Win64\crt\wchar.h" 1 occurrences found on 1 lines
294: _CRTIMP int __cdecl _wrename(const wchar_t *, const wchar_t *);
File……
楼上好强。。装了VC6.0 2005 2010 SDK。。
PS,问下用什么代码查看工具?

读书人网 >C++

热点推荐