[Program]Save 10 seconds of your life.

Hello! I've made a program that creates a "main.cpp" in a new project.It is useful for time saving I think :) The code that is written in "main.cpp" is taken from a "sc.txt" file,located in the folder with the program.You can change the content from the sc file anytime.So here is the code,you have to modify just one line I think:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <fstream>
#include <string>
#include <Windows.h>

using namespace std;
int main(){
system("title patch_v2.exe");
string  pname,tname;
string stmp,st;
fstream cpp,source;
cout<<"Enter project name: ";
getline(cin,pname);
while(pname.empty()){
	cout<<"Enter a valid project name : ";
	getline(cin,pname);
}

tname="C:\\Documents and Settings\\user name\\My Documents\\Visual Studio 2010\\Projects\\"+pname+"\\"+pname+"\\main.cpp"; 
// here ^^


cpp.open(tname,ios::out);
source.open("sc.txt",ios::in);
if(!cpp) {
	cerr<<endl<<"Unable to open project."<<endl;
	Sleep(1000);
	return 0;
}
if(!source) {
	cerr<<endl<<"Unable to open source file."<<endl;
	Sleep(1000);
	return 0;
}
while(getline(source,stmp)){
	st+=stmp+"\n";
}

cpp<<st;
cpp.close();
source.close();
cout<<endl<<"Ready to write in."<<endl;
Sleep(700);
return 0;
}
 

0.Modify the beginning of the line 19 with the address of your VC++ projects.
1.Now build the program and copy it on the desktop(for example).
2.Create a file "sc.txt" on the desktop and write in it something,for example:
1
2
3
4
5
6
7
#include <iostream>
using namespace std;
int main() {

system("pause");
return 0;
}

3.Open compiler,select new project.
4.Open the program,write in the projects name.
5.In the compiler select Source file->Add->Existing item and open main.cpp.
Ready-you saved 10 seconds of your life ;).
Of course you can edit the sc.txt file to something longer.
Hope this helped anybody :D
There's probably a way to do this with project templates in <insert whatever IDE you use here>.


... not to be a downer or anything.
Last edited on
Assuming you use IDEs as I know a few that live by the command line for everything. I use both, but feel (as stated elsewhere) that learning the command line is essential for programming.
In which case you could simply use `cp'
Assuming you use IDEs as I know a few that live by the command line for everything. I use both, but feel (as stated elsewhere) that learning the command line is essential for programming.


I don't know many people who use the command line for editing files. Most (decent) editors have a macro facility that allows you to do something similar to this without having to invoke an external program, including the editor the OP is using.
cire wrote:
I don't know many people who use the command line for editing files. Most (decent) editors have a macro facility that allows you to do something similar to this without having to invoke an external program, including the editor the OP is using.

I meant to say "live by the terminal" as they use vim, nano, or emacs and do their compilation by typing it out (ie
g++ -Wall -ansi -o prog prog.cpp 
).
Topic archived. No new replies allowed.