C++ Programmer's Cookbook

{C++ 基础} {C++ 高级} {C#界面,C++核心算法} {设计模式} {C#基础}

有用但不常见的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 );   

        }

    }

}

posted on 2005-11-04 14:55 梦在天涯 阅读(1906) 评论(2)  编辑 收藏 引用 所属分类: CPlusPlus

评论

# re: 有用但不常见的c++函数 2005-11-05 22:58 peter

是要unix平台支持的吧!  回复  更多评论   

# re: 有用但不常见的c++函数 2005-11-07 08:49 梦在天涯

不需要的啊,你可以在你的windows上可以运行的啊 !  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


公告

EMail:itech001#126.com

导航

统计

  • 随笔 - 461
  • 文章 - 4
  • 评论 - 746
  • 引用 - 0

常用链接

随笔分类

随笔档案

收藏夹

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

积分与排名

  • 积分 - 1785158
  • 排名 - 5

最新评论

阅读排行榜