有用但不常見的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;
}
//?ü??1¤×÷????
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;
//??DDê?è?
cin.getline(string,80);
cout<<"Tokens:"<<endl;
//首次分離字符串
token = strtok( string, seps );
while( token != NULL ) //?áê?·?à??D??
{
cout<<token<<endl;
//下次分離字符串 token = strtok( NULL, seps );
}
}
}posted on 2005-11-04 14:55 夢在天涯 閱讀(1937) 評論(2) 編輯 收藏 引用 所屬分類: CPlusPlus

