Code::Blocks Forums

User forums => Help => Topic started by: Matthias on May 25, 2005, 01:40:18 pm

Title: Prevent Console Application from closing to fast...
Post by: Matthias on May 25, 2005, 01:40:18 pm
Hi there,

i'm very new to programming in C (new to programming anywhere).
How can i prevent the console from closing very fast after running a programm (for instance when i compile "hello world" and let it run i see the console popping up but it closes so fast i can't recognize anything...)

Thanks for you tipps and advices!

Matthias

P.S.: Sorry for my bad englisch!
Title: Prevent Console Application from closing to fast...
Post by: aben on May 25, 2005, 02:57:19 pm
The simple solution is:

Code

int main()
{
  std::string str;
  std::cout << "Hello world!" << std::endl;
  std::cin >> str;
  return 0;
}
Title: Prevent Console Application from closing to fast...
Post by: squizzz on May 25, 2005, 05:49:28 pm
Code

#include <iostream>

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


might work fine as well...
Title: Prevent Console Application from closing to fast...
Post by: rickg22 on May 25, 2005, 06:08:14 pm
wait, didn't the console runner program do that automatically? :?
Title: Prevent Console Application from closing to fast...
Post by: squizzz on May 25, 2005, 07:01:08 pm
Quote from: rickg22
wait, didn't the console runner program do that automatically? :?

Hahaha yes it does. (checked)

But then, it doesn't seem to work for Matthias. :?
Title: Prevent Console Application from closing to fast...
Post by: mandrav on May 25, 2005, 07:44:44 pm
Quote
The simple solution is:

aben, this is the way some other IDE does it. We provide the solution without you having to edit your code ;)

Matthias, if you 're still having problems, read this thread (http://www.codeblocks.org/index.php?name=PNphpBB2&file=viewtopic&p=1647#1647).

Yiannis.
Title: Prevent Console Application from closing to fast...
Post by: aben on May 26, 2005, 10:11:59 am
Ok, the new console_runner you supplied adds this feature.
-Now I ask, is there any way to close the console automatically when my application terminates - some settings in the environment for instance?
Title: Prevent Console Application from closing to fast...
Post by: mandrav on May 26, 2005, 12:17:30 pm
Quote from: aben
Ok, the new console_runner you supplied adds this feature.

It seems that the supplied console_runner.exe with the finalbeta setup was screwed. Sorry guys.

Quote from: aben
-Now I ask, is there any way to close the console automatically when my application terminates - some settings in the environment for instance?

LOL! I never expected this. It was always the other way around  :lol:
Anyway, submit a feature request and I 'll make it configurable.

Yiannis.
Title: Prevent Console Application from closing to fast...
Post by: aben on May 26, 2005, 01:05:06 pm
Feature request submitted...
I believe that it would really begin to annoy me if I had to press enter after each run. -So for now I'll use the "screwed" version of the console_runner  :)