file copying in c++

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vasanth kumar

    file copying in c++

    Hi,

    I have a file 31oct2003.xls. I want to make a copy of this file with a new name, say:2nov2003.xl s. But my program is crashing at hte line
    char* buffer = new char[size];
    saying could not allocate memory.

    Any solution to this problem?

    ---------------------
    ifstream oldfile(31oct20 03.xls, ios::in|ios::bi nary|ios::ate);
    long size = oldfile.tellg() ;
    char* buffer = new char[size];
    oldfile.seekg (0, ios::beg);
    oldfile.read(bu ffer,size);

    ofstream weekrep(stime_1 , ios::binary||io s::out);
    weekrep.write(b uffer,size);
    -------------
    Regards,
    Vasanth
  • .oO LGV Oo.

    #2
    Re: file copying in c++


    "vasanth kumar" <vasanth.kumar@ eds.com> a écrit dans le message de news:bo2srl$o8q @nfs0.sdrc.com. ..
    Hi,

    I have a file 31oct2003.xls. I want to make a copy of this file with a new name, say:2nov2003.xl s. But my program is crashing at hte line
    char* buffer = new char[size];
    saying could not allocate memory.

    Any solution to this problem?

    ---------------------
    ifstream oldfile(31oct20 03.xls, ios::in|ios::bi nary|ios::ate);
    long size = oldfile.tellg() ;
    char* buffer = new char[size];
    oldfile.seekg (0, ios::beg);
    oldfile.read(bu ffer,size);

    ofstream weekrep(stime_1 , ios::binary||io s::out);
    weekrep.write(b uffer,size);
    -------------
    Regards,
    Vasanth
    I might be wrong, but I'd say that the value of size is zero... Chech this value first.

    Comment

    • Jacek Dziedzic

      #3
      Re: file copying in c++

      "vasanth kumar" <vasanth.kumar@ eds.com> wrote in message
      news:bo2srl$o8q @nfs0.sdrc.com. ..[color=blue]
      > Hi,
      > I have a file 31oct2003.xls. I want to make a copy of this file
      > with a new name, say:2nov2003.xl s. But my program is
      > crashing at hte line char* buffer = new char[size];
      > saying could not allocate memory.[/color]

      Check what size is before the new[].

      HTH,
      - J.

      PS. Do not, under any circumstances, post in HTML to a ng,
      especially this one or you'll get flamed.


      Comment

      • Mike Wahler

        #4
        Re: file copying in c++

        ".oO LGV Oo." <_NOSPAM_legean tvert@tiscali.f r> wrote in message
        news:bo31is$og8 $1@news.tiscali .fr...
        [color=blue]
        > I might be wrong, but I'd say that the value of size is zero... Chech
        > this value first.[/color]


        new char[0] is valid (although obviously not what OP wants).

        I suspect OP is simply requesting more memory than the
        host environment can provide.

        -Mike




        Comment

        Working...