-4

I am currently working on project where I need to add some message at the end of a file and then I want to change its extension.

I know how to add the message at the end of the file; my code:

_ofstream myfile;
_myfile.open("check.txt", std::ios_base::app);
_myfile << "Thanks for your help.\n";

How can I change the file's extension?

anatolyg
  • 26,506
  • 9
  • 60
  • 134
DeUs
  • 31
  • 2
  • 9
  • Did you consider to read the [reference documentation](http://en.cppreference.com/w/cpp/io) first? – πάντα ῥεῖ Nov 10 '16 at 13:58
  • Sorry, Currently I can not publish my code due to restrictions from my professor. – DeUs Nov 10 '16 at 14:04
  • We don't want your entire code, we want to see what you tried to fix the problem (which is hopefully only a small part of your code). Appending text to a file is a very basic thing, and @πάνταῥεῖ already linked you the documentation. Also just asking for *"give me syntax of that"* is very frowned upon, SO is not a coding service. – UnholySheep Nov 10 '16 at 14:08
  • **bold**ofstream myfile; **bold**myfile.open("check.txt", std::ios_base::app); **bold**myfile << "Thanks for your help.\n"; This is my code . But I need a solution for How to change extension of .txt file to any other format using c++? – DeUs Nov 10 '16 at 14:51
  • @Dhruval You can [edit] your post if you want to improve it. I did it for you; you can edit your post further if you want to add of change something. Also, you got an answer (see below). – anatolyg Nov 10 '16 at 14:54
  • Sorry I am New user .I don't know how to differ my code from my text.Please Help.@anatolyg and thank You – DeUs Nov 10 '16 at 14:57

1 Answers1

1

Actualy, it is very simple:

#include <iostream>
#include <fstream>
#include <cstdio>


using namespace std;


int main(int argc, char* argv[])
{

    ofstream fout("test.txt", ios_base::app);
    fout << "My cool string";
    fout.close();
    rename("test.txt", "test.txt1");

    return 0;
}
Ignat
  • 51
  • 1
  • 4