Remove and Rename using fstream

V

Venkat

Hi All,

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


regards,
Venkat
 
V

Venkat

Venkat said:
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.
 
C

CrayzeeWulf

Venkat said:
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.
 
R

Rob Williscroft

Venkat wrote in
These function's take arguments that are filenames and have type
char const *, they don't have anything to do with fstream's or

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.
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top