Remove and Rename using fstream

Discussion in 'C++' started by Venkat, Jan 8, 2004.

  1. Venkat

    Venkat Guest

    Hi All,

    Currently i guess rename and remove are not supported using fstream.
    How do i rename or remove a file?


    regards,
    Venkat
    Venkat, Jan 8, 2004
    #1
    1. Advertising

  2. Venkat

    Venkat Guest

    "Venkat" <> wrote in message
    news:1073544519.907492@sj-nntpcache-5...
    > Hi All,
    >
    > Currently i guess rename and remove are not supported using fstream.
    > How do i rename or remove a file?
    >
    >
    > regards,
    > Venkat


    Also to add, std::rename and std::remove are throwing compile errors
    saying rename and remove are not members of std, even after including
    <cstdio> library.
    Venkat, Jan 8, 2004
    #2
    1. Advertising

  3. Venkat

    CrayzeeWulf Guest

    Venkat wrote:

    > "Venkat" <> wrote in message
    > news:1073544519.907492@sj-nntpcache-5...


    >
    > Also to add, std::rename and std::remove are throwing compile errors
    > saying rename and remove are not members of std, even after including
    > <cstdio> library.
    >

    Show us the code.

    --
    CrayzeeWulf
    CrayzeeWulf, Jan 8, 2004
    #3
  4. Venkat wrote in news:1073545086.672037@sj-nntpcache-5:

    > "Venkat" <> wrote in message
    > news:1073544519.907492@sj-nntpcache-5...
    > > Hi All,
    > >
    > > Currently i guess rename and remove are not supported using fstream.


    These function's take arguments that are filenames and have type
    char const *, they don't have anything to do with fstream's or
    <stdio.h>'s FILE's.

    > > How do i rename or remove a file?
    > >


    First close any open fstream's you have associated with the file,
    then call

    std::rename( "oldname", "newname" ); or
    std::remove( "oldname" );

    Replace "oldname"/"newname" with the appropriate literals or
    char const *varaible, or use std::string's c_str() member:

    std::string name = "filename";

    std::ifstream ifs( name.c_str() );

    // read something from ifs;

    ifs.close();

    std::remove( name.c_str() );


    >
    > Also to add, std::rename and std::remove are throwing compile errors
    > saying rename and remove are not members of std, even after including
    > <cstdio> library.
    >


    How are you calling them, whats the error and what compiler are you
    using. Prefereably post some actual code (cut & paste) that doesn't
    compile.

    HTH.

    Rob.
    --
    http://www.victim-prime.dsl.pipex.com/
    Rob Williscroft, Jan 8, 2004
    #4
    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. Simon-Pierre  Jarry
    Replies:
    2
    Views:
    2,356
    Henrik
    Aug 10, 2005
  2. Armando
    Replies:
    6
    Views:
    741
    Armando
    Jan 29, 2004
  3. Matt
    Replies:
    1
    Views:
    1,443
    Victor Bazarov
    Feb 14, 2005
  4. Russell Warren
    Replies:
    5
    Views:
    367
    Fredrik Lundh
    Oct 11, 2006
  5. Greg
    Replies:
    7
    Views:
    569
    Default User
    Dec 19, 2005
Loading...

Share This Page