Small Question

Hey CPlusPlus!

Quick question here:

I'm using the MS Visual Studio C++ Express IDE, and I want to make a button so when you click it it will execute different commands inside the command line.

For example, if you wanted to change the system appearance you could type 'Control color' in the cmd, but how would I do that from C++?

I'm making a console application. So far I've managed for it to say 'Hello, World!'. Here's the entire code.

1
2
3
4
5
6
7
8
9
10
11
#include "stdafx.h";

#include <iostream>
using namespace std;

int main() 
{
   cout << "Hello World!" << endl;
   system("pause");
   return 0;
}


That opens up Hello World in the cmd. But how would I execute commands in that?

I am new to C++, so even the most simple of answers will be helpful :)

Thanks a lot!

-PG
Last edited on
If you're referring to executing console commands, you already did! :P
You used system("PAUSE"); which sends the pause command to the os. the same applies for color, or any other possible console command in the world ever. so system("COLOR FA") will change the color to whatever FA stands for.

Though, it is necessary to warn you against using calls to system(). Its a pretty nasty function, and unless you're using it for yourself only, it shouldn't be used. Its completely platform-dependent, and halts your program, calls the os, waits for the os to answer, then starts your program back up. Also, anything it runs, say you call system("start notepad.exe"), has the same privileges as the account your on. If a virus is embedded in your notepad and you're on an admin account, that virus was just ran with administrator privs.
Last edited on
Ah. I see! Is there a more safe way to load up things?

Like if I had "system("cmd.exe");" could I make that a little less nasty?

Also, I've figured out how to close the program on button click (this->Close();), but this->Minimize(); doesn't want to work. Is there a way to minimize it?

Thanks for your reply!
Also, I've figured out how to close the program on button click (this->Close();),



Umm... that doesn't work in the console. Not unless you're using some weird new API you haven't mentioned.

The 'this' keyword is meaningless when you are in a global function like main().


Is there a way to minimize it?


The console window? Not a standard way. There are platform specific ways.... but it sounds to me like you are just heavily misusing the console.

Let's back this up a bit. What kind of program are you trying to make? What is the ultimate goal here?

It sounds to me like you probably shouldn't be working in the console at all.
I was making a Windows Forms app in Visual Studio 2010.
Ah. Sounds to me like that was C++/CLI, then. Not quite C++
Topic archived. No new replies allowed.