User forums > General (but related to Code::Blocks)
Sugesstion about small changes in standard cpp code.
Angelo:
It's litttle, but useful idea.
Change standard cpp code, from:
#include <iostream>
int main()
{
std::cout << "Hello world!" << std::endl;
return 0;
}
to:
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
system("PAUSE");
return EXIT_SUCCESS;
}
imo will be great.
polygon7:
--- Quote from: Angelo on September 11, 2005, 12:02:33 pm ---#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
system("PAUSE");
return EXIT_SUCCESS;
}
--- End quote ---
If i remember correctly system("PAUSE") and return EXIT_SUCCESS are Windows specific. So this code will not be portable to other systems.
mandrav:
The system("pause") command is not windows only, but I see no reason to alter the template. Besides, C::B keeps the console program open and waits for a keypress to close it. So why use system("pause")???
If you like your template better, just save it as a user template and use it for starting new projects.
thomas:
Um... yes, it is Windows-specific. system() executes a command in the shell.
system("pause") will execute pause, which does not exist on Linux:
--- Code: ---[thomas@singularity ~]$ pause
-bash: pause: command not found
--- End code ---
Apart from that little pedantism of mine :oops:, I'd like to remark that blocking a program when it is not necessary is generally not a good idea. When a program is finished with whatever it is doing, then it should exit.
If, for whatever reason, a user wants execution to block, he can still do that from the shell, but it should not be mandatory from the program's side (unless there is a good reason, like waiting for input).
grv575:
--- Quote from: thomas on September 11, 2005, 05:44:20 pm ---Apart from that little pedantism of mine :oops:, I'd like to remark that blocking a program when it is not necessary is generally not a good idea. When a program is finished with whatever it is doing, then it should exit.
--- End quote ---
Well for the newbie, I think the window staying open is good feedback. It's confusing behavior when you hit the IDE run button and there is a quick flash of a console opening and closing (and then they have to figure out how to code it so it doesn't happen). Most console cases you do want to see any printf() results anyway.
And if you don't want this behavior then it's just as easy to run the app from explorer (IMO). I realize it's just a matter of personal preference so either way is suitable, but just think it's easier for newbies the way it is.
Navigation
[0] Message Index
[#] Next page
Go to full version