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

 

#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);
   }
}

#include<iostream.h>
#include<direct.h>
#include<errno.h>
#define MAX_PATH 250
main()
{
    //声明变量
    char *p,str[MAX_PATH];

    //设置新目录
    if (mkdir("d:\\ABC")){
        cout<<"mkdir Error!"<<endl;
    }

    //更改工作目录
    if (chdir("d:\\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("d:\\")){
        cout<<"chdir Error!"<<endl;
    }

    //删除指定目录
    if (rmdir("d:\\ABC")==-1) 
        cout<<"rmdir Error!"<<endl;
}


#include<iostream.h>
#include <string.h>

char string[80];
char seps[]   = " ,\t\n";
char *token;

void main( void )
{
    //´Ó¼üÅÌÉÏÊäÈëÁ½¸öÓï¾ä
    for (int i=1;i<3;i++) {
        cout<<"Please input a sentence:"<<endl;
        //ÕûÐÐÊäÈë
        cin.getline(string,80);             
        cout<<"Tokens:"<<endl;
        //首次分离字符串
        token = strtok( string, seps );        
        while( token != NULL )              //½áÊø·ÖÀëÅжÏ
        {
            cout<<token<<endl;
            //下次分离字符串         
                 token = strtok( NULL, seps );   
        }
    }
}

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值