who do know std::ctime() how implement? Help me?

W

wukexin

I write my own class Cfile, I want to know what about implement ctime().Who
help me?
My use function ctime, I sign it with $$$.
my class Cfile:
#------------------------
file.h
#---------------------------
#include <io.h>
#include <ctime>
#include <string>

#ifndef fileH
#define fileH
using namespace std;
bool is_path(const char* name);
//
class Cfile{
public:
bool is_path();
long size();
std::string name();
std::string attrib();
std::string create_time();
std::string access_time();
std::string write_time();
std::string date();
void display();
void print();
Cfile(const std::string& name);
Cfile(const char* name);
~Cfile();
protected:
bool initialize(const char* name);
bool clean();
char m_full_fname[260];
long m_hFile;
struct _finddata_t m_fileinfo; //file_information
};
#endif //fileH
#-------------------------
file.cpp
#---------------------------

#include <string>
#include <cstring>
#include <ctime>
///////////////
#include "dir.h"
//////////////////////////
#include "e:\program\wukexin\file\file.h"
#include "e:\program\wukexin\timer\timer.h"
#include "e:\program\wukexin\tracer\tracer.h"
#include "e:\program\wukexin\help\help.h"
//
Cfile::Cfile(const std::string& name){
#ifdef DEBUG
#endif //
initialize( name.c_str() );
};
//
Cfile::Cfile(const char* name){
#ifdef DEBUG
Ctracer tracer( string("Cfile"),string(name) );
Ctimer timer( string("Cfile"), string(name));
#endif //debug
initialize(name);
};
//
Cfile::~Cfile(){
#ifdef DEBUG
Ctracer tracer("Cfile::~Cfile()");
Ctimer timer("Cfile::~Cfile()");
#endif //
clean();
};
//
bool Cfile::initialize(const char* name){
#ifdef DEBUG
//string message("initialize"),arg(name);
Ctracer tracer( string("initialize"), string(name) );
Ctimer timer( string("initialize"), string(name) );
#endif //
bool result(false);
#ifdef __BORLAND__
const int PATHMAX=260;
char temp[PATHMAX];
strcpy(temp,name);
m_hFile=_findfirst( temp, &m_fileinfo);
#else
m_hFile=_findfirst( name, &m_fileinfo);
#endif //borland
if( -1 != m_hFile ){
result=true;
}
#ifdef DEBUG
tracer.append( to_string(m_hFile) );
#endif //debug
return result;
};
bool Cfile::clean(){
#ifdef DEBUG
Ctracer tracer("Cfile::clean()");
Ctimer timer("Cfile::clean()");
#endif //debug

#ifdef __BORLAND__
cout<<"m_hFile="<<m_hFile<<endl;
#else
#endif //borland
bool result(false);
if( 0 == _findclose(m_hFile) ){
result=true;
}
#ifdef DEBUG
tracer.append( to_string(result) );
#endif //debug
return result;
};
//
bool Cfile::is_path(){
#ifdef DEBUG
Ctracer tracer( "Cfile::is_path()" );
Ctimer timer( "Cfile::is_path()" );
#endif //
bool result(false);
if( m_fileinfo.attrib & _A_SUBDIR ){
result=true;
}
return result;
};
//
long Cfile::size(){
#ifdef DEBUG
Ctracer tracer("Cfile::size()");
Ctimer timer("Cfile::size()");
#endif //
long result(m_fileinfo.size);
return result;
};
//
string Cfile::name(){
#ifdef DEBUG
Ctracer tracer("Cfile::name()");
Ctimer timer("Cfile::name()");
#endif //
string result(m_fileinfo.name);
return result;
};
//
string Cfile::attrib(){
#ifdef DEBUG
Ctracer tracer("Cfile::attrib()");
Ctimer timer("Cfile::attrib()");
#endif //
string result;
if( m_fileinfo.attrib & _A_SUBDIR ){
result.append("d");
}
if( m_fileinfo.attrib & _A_HIDDEN ){
result.append("h");
}
if( m_fileinfo.attrib & _A_ARCH ){
result.append("a");
}
if( m_fileinfo.attrib & _A_RDONLY ){
result.append("r");
}
if( m_fileinfo.attrib & _A_SYSTEM ){
result.append("s");
}
if( m_fileinfo.attrib & _A_VOLID ){
result.append("l");
}
if( !result.empty() ){
result.insert(result.begin(),1,'-');
}
#ifdef DEBUG
tracer.append(result);
#endif //debug
return result;
};
//
string Cfile::create_time(){
#ifdef DEBUG
Ctracer tracer("");
Ctimer timer("");
#endif //
string result;
return result;
};
//
string Cfile::access_time(){
#ifdef DEBUG
Ctracer tracer("");
Ctimer timer("");
#endif //
string result;
return result;
};
//
string Cfile::write_time(){
#ifdef DEBUG
Ctracer tracer("");
Ctimer timer("");
#endif //
string result;
time_t *ptr=&m_fileinfo.time_write;
result=ctime(ptr);//$$$
#ifdef DEBUG
tracer.append(result);
#endif //DEBUG
return result;
};
//
string Cfile::date(){
#ifdef DEBUG
Ctracer tracer("");
Ctimer timer("");
#endif //
string result;
return result;
};
//
void Cfile::display(){
#ifdef DEBUG
Ctracer tracer("Cfile::display()");
Ctimer timer("Cfile::display()");
#endif //
};
//
void Cfile::print(){
#ifdef DEBUG
Ctracer tracer("Cfile::print()");
Ctimer timer("Cfile::print()");
#endif //
};
 
K

Karl Heinz Buchegger

wukexin said:
I write my own class Cfile, I want to know what about implement ctime().Who
help me?
My use function ctime, I sign it with $$$.

So what *is* your problem?

* Do you get a compiler error?
If yes, which one

* Do you have problems at runtime?
If yes, where?

* Do you want to implement the function ctime() by yourself?
If yes, where is your problem in implementing that function?
ctime() takes a pointer to a time_t structure and creates
a standard formatted string. The time_t structure contains
everything needed for doing that, so all in all it is basically
a wrapper around a printf() with a fixed format string.

You don't go to your doctor and tell him: It hurts, help me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,961
Messages
2,570,130
Members
46,689
Latest member
liammiller

Latest Threads

Top