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::rename(3) C++ Standard Libary std::rename(3)

std::rename - std::rename


Defined in header <cstdio>
int rename( const char *old_filename, const char *new_filename );


Changes the filename of a file. The file is identified by character string pointed
to by old_filename. The new filename is identified by character string pointed to by
new_filename.


If new_filename exists, the behavior is implementation-defined.


old_filename - pointer to a null-terminated string containing the path identifying
the file to rename
new_filename - pointer to a null-terminated string containing the new path of the
file


0 upon success or non-zero value on error.


POSIX specifies many additional details on the semantics of this function, which are
reproduced in C++ by std::filesystem::rename.

// Run this code


#include <iostream>
#include <fstream>
#include <cstdio>
int main()
{
bool ok{std::ofstream("from.txt").put('a')}; // create and write to file
if (!ok) {
std::perror("Error creating from.txt");
return 1;
}


if (std::rename("from.txt", "to.txt")) {
std::perror("Error renaming");
return 1;
}


std::cout << std::ifstream("to.txt").rdbuf() << '\n'; // print file
}


a


rename moves or renames a file or directory
(C++17) (function)
remove erases 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.