代码改变世界

stdio.h中的rename函数

2010-08-12 22:00  abstract code  阅读(266)  评论(0编辑  收藏  举报

 

rename可以移动或者重命名一个文件。

#include <iostream>
#include <stdio.h>
#include <cstdlib>
using namespace std;

int main(int argc, _TCHAR* argv[])
{
    char oldname[] = "hedy.txt";
    char newname[] = "D:\\yes.txt";
    int result;

    result = rename(oldname, newname);

    if ( result == 0 )
        puts ( "File successfully renamed" );
    else
        perror( "Error renaming file" );
    
    system("pause");
    return 0;
}