how to do that in c++ programming

Status
Not open for further replies.

google-fiber

Estimable
Sep 18, 2015
5
0
4,510
0
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
 

TechyInAZ

Admirable
Moderator
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
23


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
23


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.
Thread starter Similar threads Forum Replies Date
Neon The (Anthro) Umbreon Apps General Discussion 1
K Apps General Discussion 2
T Apps General Discussion 10
M Apps General Discussion 2
R Apps General Discussion 3
S Apps General Discussion 2
N Apps General Discussion 1
P Apps General Discussion 4
A Apps General Discussion 8
M Apps General Discussion 6
S Apps General Discussion 1
C Apps General Discussion 5
H Apps General Discussion 3
A Apps General Discussion 1
U Apps General Discussion 1
F Apps General Discussion 3
F Apps General Discussion 7
S Apps General Discussion 4
A Apps General Discussion 1
9 Apps General Discussion 1

ASK THE COMMUNITY