# C++ simple question!



## adz_619 (Jul 21, 2007)

Hi!
Below is code:

_#include <iostream>

using namespace std;

int main ()
{
cout << "Hello, World!\n";
return 0;
}_

Can someone tell me which IDE (not standalone compiler) will compile this code without any problems? Dev-cpp does not work properly with this code!


----------



## shuuhen (Sep 4, 2004)

What errors are you getting? It should work fine with Dev-C++ as long as you're compiling it as C++ code. Make sure Dev-C++ is compiling it as C++ code. Might as well make sure the program is saved with a .cpp extension as well (I've heard some Windows IDE's guess based on extension, but I don't do much in Windows).


----------



## adz_619 (Jul 21, 2007)

shuuhen said:


> What errors are you getting? It should work fine with Dev-C++ as long as you're compiling it as C++ code. Make sure Dev-C++ is compiling it as C++ code. Might as well make sure the program is saved with a .cpp extension as well (I've heard some Windows IDE's guess based on extension, but I don't do much in Windows).


Works fine, but the book I am following says that the program should appear on the screen and display 'hello world'. In dev-cpp it runs , before quickly closing!


----------



## shuuhen (Sep 4, 2004)

That's just the way Windows does command line windows. You'll need to do something to make it wait for a while or just run the program from a command line (DOS) window that's already open.

Has your book taught you how to use cin (like cout, but for getting input instead of sending stuff to the screen? You could use that to just wait for the user to press enter.


----------



## MattBro (Nov 11, 2006)

I suggest Visual C++ Express 2008.


----------



## Bookworm99 (Jun 5, 2007)

Hey,

Yes, that's the problem with Dev-C++. It requires you to manually pause the program at the end in order to display the 'press any key to continue'. That said, it is much better a compiler then Visual C++, in my humble opinion. 

Try adding this at the end of your program (before return 0:


```
system("PAUSE");
```
You might need to add the includes: 

```
#include<cstdio>
#include<cstdlib>
```


----------



## frantheonlyter (Nov 29, 2007)

You should maybe try to learn programming on Linux systems, much more hassle free for beginners.


----------



## Bookworm99 (Jun 5, 2007)

Probably; however, using Windows will be a good foundation since most people use it. 

Dang market share...


----------



## shuuhen (Sep 4, 2004)

Bookworm99 said:


> Probably; however, using Windows will be a good foundation since most people use it.


 Learning on Linux would be good since it does not need a programmer to use workarounds to make command line windows to stay open. If a program runs on Linux without much (or any) OS specific code, it should be easier to port to a large number of OSs, while on Windows people sometimes use things like system("PAUSE"); which add up to make a program fairly Windows specific. What do you do when you have a flashy game made with DirectX and other Windows specific technologies and you get a lot of users wanting the game on Linux or Mac OS X? There are many users (including myself) that only use Windows for work/school projects. Matter of fact, the only reason I use Windows for those projects is the company that produces the program I need still doesn't do a very good job programming for other OSs.

The bottom line is that a programmer should understand how to write code to be as portable as possible (assuming the language in question isn't platform specific itself). Either OS works as long as a programmer learns how to write good code (maybe even great code).


----------



## lensman3 (Oct 19, 2007)

I agree shuuhen about learning Unix/Linux. Compiling programs is a lot easier in Linux. 

A possible compromise is downloading "cygwin" and installing it under XP/2000/64. Download enough modules to compile a program. Cygwin is a Unix port to the Microsoft windows world. Go to "www.cygwin.com" and download the setup.exe program. Since it runs under windows you have access to the files using your favorite windows editor. Or you can bit the bullet and learn VI/VIM or emacs. The default shell is bash.

I find cygwin to be much slower than Linux, but that is due to windows and the overhead imposed by XP. But all the compiler are there: C/C++(version 3.44), fortran, make, automake, yacc, bison/flex, curses, X-11, gdb, rcs/sccs, etc. 

Shuuhen's last paragraph is especially pertinent: how to write code to be as portable as possible. Cygwin just gives you another option. In fact, install Linux and Cygwin both and compile under both environments. Porting between the two WILL make your code better!


----------

