gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > C++ Compiler

#96233 - KINGOFNOOBS - Tue Aug 01, 2006 11:34 pm

I need a good compiler.

http://www.cplusplus.com/doc/tutorial/program_structure.html

i am doing that tutorial. I tried using Dev C++ but it didnt work. any good compilers?

#96235 - Dwedit - Tue Aug 01, 2006 11:55 pm

If dev c++ isn't working for something that simple, you're doing it wrong. Make sure you downloaded the full version of dev c++ which includes the gcc compiler, not just the IDE.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#96236 - Optihut - Tue Aug 01, 2006 11:56 pm

Why doesn't devc++ work for you? The program compiles just fine for me. However, since there is no pause in it, you can't really see the output, because the compiler window closes immediately after the program ends.

If you don't want to put in a pause, run the compiled exe file in a dos box and you can see the output as well.

#96242 - KINGOFNOOBS - Wed Aug 02, 2006 12:38 am

Code:
// my first program in C++

#include <iostream>
using namespace std;

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


When i compile that the MS-DOS console appears and quickly goes away. Anyone having the same problem?

#96246 - Dwedit - Wed Aug 02, 2006 12:57 am

Add to the top:
#include <cstdlib>

and before return 0;
system("pause");
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#96293 - Optihut - Wed Aug 02, 2006 10:32 am

KINGOFNOOBS wrote:
When i compile that the MS-DOS console appears and quickly goes away. Anyone having the same problem?


It's not a "problem", it's perfectly normal. Also, I already mentioned in the post above yours that the window closes after the execution of the program. Therefore you need to put in a pause.

EDIT: And I have to admit that my own method of putting in a pause (which I didn't mention for that very reason) would have been frowned upon (using scanf), but Dwedit showed how it could be done :)

#96511 - sgeos - Thu Aug 03, 2006 5:25 pm

Untested, but this is the function I use in C:
Code:
#define LINE_MAX 82
void waitForInput(void)
{
  char buffer[LINE_MAX];
  fgets(buffer, sizeof(buffer), stdin);
}

Then call waitForInput() before your final return. You might want to put it at the end of your cleanup routine. Then again... you might not. =)

-Brendan