Returning Nothing

Apr 18, 2012 at 6:38am
Every time I type in a code; I keep on getting this message when I run it:

Process returned 0 <0x0> Execution time: (time) s
Press any key to continue.

No matter what I type. Even the tutorial doesn't work
1
2
3
4
5
6
7
8
#include iostream
using namespace std;

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

It keeps on returning the same thing over and over again

I'm using Code::Block 10.05 compiler.
Apr 18, 2012 at 6:43am
Try
1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;

int main()
{
  cout << "Hello World!";
  cin.get();
  return 0;
}
The point is that the program probably closes before you get to see anything. Console programs are intended to be ran from console. cin.get() is a bit of a hack.
Although I remember code blocks doing the pause on its own..

edit: ignore me, I misunderstood the problem.
Last edited on Apr 21, 2012 at 7:02am
Apr 18, 2012 at 12:19pm
It doesn't have anything to do with his program.

I believe it is a Code::Blocks message, but I could be wrong. In any case, it is something your IDE or shell is doing.

Personally, I always test command-line programs from the command-line. If part of your issue is that you like the "Press any key to continue" before the pop-up command prompt disappears, see http://cplusplus.com/articles/iw6AC542/

Hope this helps.
Apr 20, 2012 at 11:21am
I think it Code::Block too. Can you recommend a easy compiler for beginners?
Apr 20, 2012 at 11:41am
It only shows that message if you run the program directly from code::blocks. If you run the program by opening the .exe file from wherever it's saved then you won't get this message. Although, you won't see "Hello World!" printed on the screen because you haven't put in any code to keep the console window open.
Last edited on Apr 20, 2012 at 11:42am
Apr 20, 2012 at 3:37pm
There's nothing wrong with C::B, it's just giving you useful information about how your program executed.
Apr 23, 2012 at 9:42am
Although, you won't see "Hello World!" printed on the screen because you haven't put in any code to keep the console window open.


So how to fix this?
Apr 23, 2012 at 10:38am
Provide a screenshot of the problem.
Apr 23, 2012 at 1:48pm
So how to fix this? 


Put #include <limits> at the top of the code and the following two lines of code before return 0;:

1
2
cout<<endl<<"Press ENTER to continue...";
cin.ignore(numeric_limits<streamsize>::max(),'\n');
Apr 24, 2012 at 12:02pm
Ok, will try.

Can you please explain what does 'end1', 'ignore' and 'numeric_limits' do? I'm still new at this.
Apr 24, 2012 at 12:16pm
endl - End line command. Inserts newline character, flushes buffer. http://www.cplusplus.com/reference/iostream/manipulators/endl/

ignore - Member function of the istream class (cin is an instance of that class). http://www.cplusplus.com/reference/iostream/istream/ignore/

numeric_limits - Templated class that holds properties for different data types. In this case, a signed int or long.
http://www.cplusplus.com/reference/std/limits/numeric_limits/
http://www.cplusplus.com/reference/iostream/streamsize/
Apr 24, 2012 at 8:07pm
@iHutch105
That will not fix his issue, it only adds to it. Also:

@Jlm07
That really is not a good thing to put in console programs. While I have written an Article about this ( http://www.cplusplus.com/articles/iw6AC542/ ), keep in mind that console applications are very much restricted when you do things like that.

Again, all you are seeing is something your IDE is doing for your benefit. If you want to see how your program will actually run from the console, go to Start, click the Run edit box, type in "cmd" (without the quotes), and press ENTER. Once there, you can set the drive and directory to where your program's executable is, and then run it by typing its name.

Er, I've got to take my kid to baseball now.
Apr 24, 2012 at 8:37pm
Duoas,

Sorry, I wasn't really suggesting a fix. I saw the latest posts and gave a brief explanation of what he asked.
Topic archived. No new replies allowed.