有用但不常见的c++函数

简介:

 1、

#include<iostream.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
 
void  main( void  )
{
     struct  stat buf;
     int  result;
 
     //获得c:\Windows\Calc.exe文件的信息
     result =stat( "c:\\windows\\Calc.exe" , &buf );
 
     //显示cal.exe的文件状态信息
     if ( result != 0 )
         perror( "Problem getting information"  );
     else
     {
         cout<< "Size of the file in bytes:" <<buf.st_size<<endl;
         cout<< "Drive number of the disk containing the file :" ;
         cout<< char (buf.st_dev + 'A' )<<endl;
         cout<< "Time of creation of the file:"  << ctime(&buf.st_ctime);
         cout<< "Time of last access of the file:"  << ctime(&buf.st_atime);
         cout<< "Time of last modification of the file:"  << ctime(&buf.st_mtime);
     }
}

  

2、

#include<iostream.h>
#include<direct.h>
#include<errno.h>
#define MAX_PATH 250
int  _tmain( int  argc, _TCHAR* argv[])
{
     char * p, str[MAX_PATH];
     //创建新目录
     if  (mkdir( "E:\\ABC" ))
     {
         cout << "mkdir Error!"  << endl;
     }
     //更改工作目录
     if  (chdir( "E:\\ABC" ))
     {
         cout << "chdir Error!"  << endl;
     }
 
     //读取当前的目录
     if  ((p = getcwd(str,MAX_PATH))==NULL)
     {
         cout << "getcwd Error!"  << endl;
     }
     else
     {
         cout << "p: "  << p<< endl;
         cout << "str: "  << str << endl;
     }
 
     //更改工作目录
     if  (chdir( "E:\\" ))
     {
         cout << "chdir Error!"  << endl;
     }
 
     //删除指定目录,如果目录为工作目录,则不能删除
     if  (rmdir( "E:\\ABC" )==-1)
         cout<< "rmdir Error!" <<endl;
 
     return  0;
 
 
}

 原文:http://www.cppblog.com/mzty/archive/2005/11/04/936.html 



本文转自Work Hard Work Smart博客园博客,原文链接:http://www.cnblogs.com/linlf03/archive/2011/11/18/2253483.html,如需转载请自行联系原作者

目录
相关文章
|
7月前
|
存储 容器
函数的学习与使用
函数的学习与使用
|
8月前
|
存储 编译器 文件存储
|
10月前
|
存储 Shell C++
零基础学会python编程——输入 / 输出函数与变量
零基础学会python编程——输入 / 输出函数与变量
187 0
数组的解释及使用方法
数组的解释及使用方法
100 0
|
程序员 编译器 C语言
学C的第九天(深入学习函数:库函数、自定义函数、函数的参数、函数调用、练习、补充知识点)-1
1.函数是什么: 维基百科中对函数的定义:子程序 * 在计算机科学中,子程序(英语:
107 0
|
程序员
学C的第九天(深入学习函数:库函数、自定义函数、函数的参数、函数调用、练习、补充知识点)-2
5.5:练习(部分上一期做过,换成函数做法): (1).写一个函数可以判断一个数是不是素数:
|
编译器
学习函数
学习函数
118 0
|
存储 安全 编译器
C#编程深入研究变量,类型和方法(一)
C#编程深入研究变量,类型和方法
C#编程深入研究变量,类型和方法(一)