ssum_way's blog

By ssum_way, history, 6 years ago, In English

I use ST3 to build my cpp programs. I'm trying to find if there is a way where every time I build my program, it creates a copy of the program in some other directory, kind of like how CHelper in Java creates a final output file in one location. I want this so that I can easily submit my file on codeforces, so I don't have to locate my file every time I solve a new problem.

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
6 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

If you are on linux you can do it like this.I do it this way.
Suppose now you are compiling the file 459c.cpp and the you want to submit the target file that is ~/path/to/your/file/output.cpp.
Now after compiling the file what you can do is type this command(use > operator)
cat 459c.cpp > ~/path/to/your/file/output.cpp.
This will copy 459c.cpp to output.cpp in your target folder.
I know that is a very big command to write during a competition so to make life easier you can convert it into a function and add it to your .bashrc file.
Just add this function in your .bashrc file.

copy() {
cat "$1" > ~/path/to/your/file/output.cpp
}


Now you can just type copy 459c.cpp and it will be in your target file in a second.
Or if you are using vim then it is even more awesome.You can just map a key to this function. `

»
6 years ago, # |
  Vote: I like it +13 Vote: I do not like it

You can use a Makefile for that. In short, a Makefile contains a list of things system knows how to "make". On linux, by default (i.e. via a systemwide Makefile), if you type make yourfile (and there is yourfile.cpp in the corresponding directory) it will run g++ yourfile.cpp -o yourfile. By putting a file called Makefile in that directory, you can change what is being built.

A recipe contains the name of what you want to build, its dependencies (if none of these files changed since last make, it will decide there is nothing new to make) and its commands, in your case compile and copy. A simple Makefile that does what you want would be:

yourfile: yourfile.cpp
   g++ yourfile.cpp -o yourfile
   cp yourfile.cpp path/to/copy/destination/otherfile.cpp

Note that this can compile only a program with a name yourfile.cpp, but I chose it for simplicity. Makefile can use a wildcard and then compile any cpp file (just like the systemwide one does). Check out this tutorial for an example of how to do that.

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Why would you want to create a copy of the program in some other directory? Don't you do all the work in separate folders for each contest? And even if it's all in one folder, can't you always sort by modified time? I am not criticizing, just wondering.