zoukankan      html  css  js  c++  java
  • 有用但不常见的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 

  • 相关阅读:
    hihocoder1634 Puzzle Game
    hihocoder1580 Matrix
    BZOJ3036 绿豆蛙的归宿
    CF|codeforces 280C Game on Tree
    [SDOI2011] 计算器
    [SCOI2007] 修车
    [JSOI2008] 球形空间产生器sphere
    APIO2012 派遣dispatching | 左偏树
    OI数据结构&&分治 简单学习笔记
    BZOJ3307 雨天的尾巴
  • 原文地址:https://www.cnblogs.com/linlf03/p/2253483.html
Copyright © 2011-2022 走看看