GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::remove(3) C++ Standard Libary std::remove(3)

std::remove - std::remove


Defined in header <cstdio>
int remove( const char* fname );


Deletes the file identified by character string pointed to by fname.


If the file is currently open by the current or another process, the behavior of
this function is implementation-defined (in particular, POSIX systems unlink the
file name, although the file system space is not reclaimed even if this was the last
hardlink to the file until the last running process closes the file, Windows does
not allow the file to be deleted)


fname - pointer to a null-terminated string containing the path identifying the file
to delete


0 upon success or non-zero value on error.


POSIX specifies many additional details for the behavior of this function.


The standard library also defines a function template std::remove taking a pair of
iterators and a value, this overload is one of the standard algorithms.

// Run this code


#include <iostream>
#include <fstream>
#include <cstdio>
int main()
{
bool ok = static_cast<bool>(std::ofstream("file1.txt").put('a')); // create file
if(!ok) { std::perror("Error creating file1.txt"); return 1; }
std::cout << std::ifstream("file1.txt").rdbuf() << '\n'; // print file


std::remove("file1.txt"); // delete file


bool failed = !std::ifstream("file1.txt");
if(failed) { std::perror("Error opening deleted file"); return 1; }
}


a
Error opening deleted file: No such file or directory


remove removes a file or empty directory
remove_all removes a file or directory and all its contents, recursively
(C++17) (function)
(C++17)
rename renames a file
(function)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.