| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 504 人关注过本帖
标题:c++中可以重新命名文件吗
只看楼主 加入收藏
wfjt
Rank: 1
等 级:新手上路
帖 子:121
专家分:0
注 册:2007-11-30
收藏
 问题点数:0 回复次数:1 
c++中可以重新命名文件吗
比如e.txt命名为e.hrt
搜索更多相关主题的帖子: 命名 
2007-12-01 11:56
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
得分:0 
rename function
int rename ( const char * oldname, const char * newname ); <cstdio>

Rename file

Changes the name of the file or directory specified by oldname to newname.
If oldname and newname specify different paths and this is supported by the system, the file is moved to the new location.
This is an operation performed directly on a file; No streams are involved in the operation.


Parameters
oldname
C string containing the name of the file to be renamed and/or moved. This file must exist and the correct writing permissions should be available.
newname
C string containing the new name for the file. This shall not be the name of an existing file; if it is, the behavior to be expected depends on the running environment, which may either be failure or overriding.

Return value
If the file is successfully renamed, a zero value is returned.
On failure, a nonzero value is reurned and the errno variable is set to the corresponding error code. Error codes are numerical values representing the type of failure occurred. A string interpreting this value can be printed to the standard error stream by a call to perror.

Example
/* rename example */
#include <stdio.h>

int main ()
{
  int result;
  char oldname[] ="oldname.txt";
  char newname[] ="newname.txt";
  result= rename( oldname , newname );
  if ( result == 0 )
    puts ( "File successfully renamed" );
  else
    perror( "Error renaming file" );
  return 0;
}
 

If the file oldname.txt could be succesfully renamed to newname.txt the following message would be written to stdout:
File successfully renamed

Otherwise, a message similar to this will be written to stderr:
Error renaming file: Permission denied


See also
remove Remove file (function)

I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-12-01 14:04
快速回复:c++中可以重新命名文件吗
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038115 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved