linux 文件流无法关闭吗,关于C++ 在linux下面文件流的有关问题 大牛

C/C++ code#include "nfx.h"

//#ifdef LINUX_PLATFORM

#include

#include

#include

#include

#include

#include

//#endif

#include

#include

#include

#include

#include

#include "Log.h"

using namespace std;

/******************************************************/

/**/const U32 DefLogLevel = CLOG_LEVEL_ALL;

/******************************************************/

const char* LogFileDir = "./Log";

void CLog::init( void )

{

}

CLog::CLog( void ):m_tid(pthread_self( ))

{

this->init( );

}

void CLog::getThreadName( char* threadName )

{

DIR* dp;

struct dirent* entry;

struct stat statbuf;

if( ( dp = opendir( LogFileDir ) ) == NULL )

{

fprintf( stderr,"cannot open directory \n");

return;

}

//chdir( dir );

while( ( entry = readdir( dp ) )!=NULL )

{

lstat( entry->d_name,&statbuf );

if( !S_ISDIR( statbuf.st_mode ) )

{

fstream logfile;

logfile.open( entry->d_name,ifstream::in );

logfile.seekg(0,fstream::beg);

string titlebuf;

cout<d_name<

while(logfile>>titlebuf)

{

cout<

}

fstream::iostate oldstate = logfile.rdstate( );

logfile.close();

}

}

}

CLog::CLog( char * threadName ):m_tid(pthread_self( ))

{

this->init( );

getThreadName( threadName );

}

CLog::~CLog()

{

}

void CLog::formatPrint(const char *title,va_list args )

{

FILE * filestream = fopen("./Log/DebugLog","a");

fprintf(filestream,"\n<===FILE : %s LINE : %d DATA : %s TIME : %s===>\n",__FILE__,__LINE__,__DATE__,__TIME__);

vfprintf(filestream,title,args);

fprintf(filestream,"\n");

fclose(filestream);

}

void CLog::Log(U32 level,const char * title,...)

{

if(DefLogLevel & level)

{

va_list arg_ptr;

va_start( arg_ptr,title );

this->formatPrint(title, arg_ptr );

va_end( arg_ptr );

}

}

void CLog::Logif( U32 level,bool condition,const char * title,... )

{

if(condition && (DefLogLevel & level))

{

va_list arg_ptr;

va_start( arg_ptr,title );

this->formatPrint( title,arg_ptr );

va_end( arg_ptr );

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值