how to do that in c++ programming

Status
Not open for further replies.

google-fiber

Estimable
Sep 18, 2015
5
0
4,510
since the website is called toms hardware, i dont think i should be asking a programming question, but ill give it a try, im teaching myself c++, so can somebody teach me how to do this:

int main() {
cout << "type 1 or 2";
int x;
cin x;
if (x==1) { /* open notepad*/}
if (x==2) {/* open paint */}
}


how to open and close apps from c++ console application
 
This is a hardware site, so yeah programming isn't really our thing. However, it's not illegal to ask it here. But, I doubt you'll get a answer here.

There are roomers that Tom's might create another site specifically for programmers, however it's not going to be for a LONG time.
 

itmoba

Estimable
Aug 14, 2015
153
0
4,660


I'm going to assume you're targeting Windows based on "notepad" and "paint". Thus, you're looking to use CreateProcess().
 

What do you think will be easier for a newbie:
1. system() function with a single parameter, command-line
2. CreateProcess() with dozen of parameters, some of them poorly documented?
 

itmoba

Estimable
Aug 14, 2015
153
0
4,660


Programming is not about quick shortcuts. When learning any computer language, it's best practice to learn the most prudent, safest, and practical means of implementation from the very start. To do otherwise is to teach nasty habits which may work in the short-term but will not suffice over the long-term.

system() will execute a command from a newly created instance of cmd.exe. This means MyProgram -> system() -> cmd.exe -> [Program_I_want_to_Open].

CreateProcess() is more direct, meaning 'cmd.exe' is not a middle-man agent. So, unlike the example above, relying on this call means MyProgram -> CreateProcess() -> [Program_I_want_to_Open]. Doing so is safer because the invoked action forcibly sets the result to occur at the user's permissions.
 
Status
Not open for further replies.