(C++) StdRenameExample1
February 24, 2017 · View on GitHub
(C++) StdRenameExample1
Technical facts
Operating system(s) or programming environment(s)
Lubuntu 15.04 (vivid)
Qt Creator 3.1.1
- G++ 4.9.2
Libraries used:
STL: GNU ISO C++ Library, version
4.9.2
Qt project file: ./CppStdRenameExample1/CppStdRenameExample1.pro
TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += main.cpp
./CppStdRenameExample1/main.cpp
#include <cassert> #include <fstream> ///Determines if a filename is a regular file ///From http://www.richelbilderbeek.nl/CppIsRegularFile.htm bool IsRegularFile(const std::string& filename) { std::fstream f; f.open(filename.c_str(),std::ios::in); return f.is_open(); } int main() { const std::string before = "a.tmp"; const std::string after = "b.tmp"; //Delete possible previous files std::remove(before.c_str()); std::remove(after.c_str()); assert(!IsRegularFile(before)); assert(!IsRegularFile(after)); //Create before { std::ofstream f(before.c_str()); } assert( IsRegularFile(before)); assert(!IsRegularFile(after)); //Rename before to after { std::rename(before.c_str(),after.c_str()); } assert(!IsRegularFile(before)); assert( IsRegularFile(after)); //Delete files std::remove(before.c_str()); std::remove(after.c_str()); assert(!IsRegularFile(before)); assert(!IsRegularFile(after)); }