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

Discussion in 'C++' started by wukexin, May 25, 2005.

  1. wukexin

    wukexin Guest

    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 //
    };
    wukexin, May 25, 2005
    #1
    1. Advertising

  2. wukexin wrote:
    >
    > 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.

    --
    Karl Heinz Buchegger
    Karl Heinz Buchegger, May 25, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin

    ctime Help

    Kevin, May 16, 2004, in forum: C++
    Replies:
    3
    Views:
    789
    osmium
    May 16, 2004
  2. Hao Xu
    Replies:
    2
    Views:
    731
    Mark McIntyre
    Aug 17, 2004
  3. B Williams

    Help with C++ <ctime>

    B Williams, Jul 10, 2006, in forum: C++
    Replies:
    8
    Views:
    3,666
    Ron Natalie
    Jul 10, 2006
  4. Replies:
    7
    Views:
    497
    Steve Pope
    Oct 3, 2006
  5. Andries

    I know, I know, I don't know

    Andries, Apr 23, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    228
    Gregory Toomey
    Apr 23, 2004
Loading...

Share This Page