Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,121 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,756 people online right now. Registration is fast and FREE... Join Now!




Help with Dev C++

 
Reply to this topicStart new topic

Help with Dev C++

jarmanator
25 May, 2007 - 10:50 AM
Post #1

New D.I.C Head
*

Joined: 25 May, 2007
Posts: 1


My Contributions
Here is my problem. I downloaded Dev-C++ by Bloodshed. I can't seem to get a simple cout statement to work.

#include (iostream)

int main()
{
cout<<"Hello World!\n";
}

This should work with a normal compiler, but this program just opens up the box and immediately closes. The only thing that works is while statements! SOMEONE HELP!
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Help With Dev C++
25 May, 2007 - 10:55 AM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,442



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
QUOTE(jarmanator @ 25 May, 2007 - 11:50 AM) *

Here is my problem. I downloaded Dev-C++ by Bloodshed. I can't seem to get a simple cout statement to work.

#include (iostream)

int main()
{
cout<<"Hello World!\n";
}

This should work with a normal compiler, but this program just opens up the box and immediately closes. The only thing that works is while statements! SOMEONE HELP!


Try this...

CODE

#include <iostream.h>

int main() {
  cout<<"Hello World!\n";

  return 0; // if it's type int, you need to return an integer
}


User is online!Profile CardPM
+Quote Post

quim
RE: Help With Dev C++
25 May, 2007 - 10:55 AM
Post #3

D.I.C Head
Group Icon

Joined: 11 Dec, 2005
Posts: 145



Thanked: 2 times
Dream Kudos: 350
My Contributions
CODE
#include (iostream)


this is suppose to be like...:

CODE
#include <iostream>

here is simple hello world program:
CODE
#include <iostream>//notice that .h is no use - .h is for C language
using namespace std;
int main()
{
cout << "Hello World!";
return 0;
}


EDITED:
oops sorry when we posted at same time
there was no reply when i posted this


This post has been edited by quim: 25 May, 2007 - 11:14 AM
User is offlineProfile CardPM
+Quote Post

Algorythm
RE: Help With Dev C++
25 May, 2007 - 10:59 AM
Post #4

New D.I.C Head
*

Joined: 17 May, 2007
Posts: 10


My Contributions
>>This should work with a normal compiler,
Dev-C++ is a normal compiler. sad.gif

>>but this program just opens up the box and immediately closes
That's because it's done. It printed the message and found nothing else to do, so the process that spawned the window terminates and the window goes bye-bye as well. To get around that and still run from the IDE, you can pause for input:
CODE

#include <iostream>

int main() {
  std::cout<<"Hello World!\n";
  std::cout<<"Press Enter to continue . . \n";
  std::cin.get();
}

User is offlineProfile CardPM
+Quote Post

MorphiusFaydal
RE: Help With Dev C++
4 Jun, 2007 - 10:23 PM
Post #5

D.I.C Lover
Group Icon

Joined: 12 May, 2005
Posts: 1,104



Thanked: 8 times
Expert In: Hardware, Networking

My Contributions
QUOTE(Algorythm @ 25 May, 2007 - 11:59 AM) *

>>This should work with a normal compiler,
Dev-C++ is a normal compiler. sad.gif

>>but this program just opens up the box and immediately closes
That's because it's done. It printed the message and found nothing else to do, so the process that spawned the window terminates and the window goes bye-bye as well. To get around that and still run from the IDE, you can pause for input:
CODE

#include <iostream>

int main() {
  std::cout<<"Hello World!\n";
  std::cout<<"Press Enter to continue . . \n";
  std::cin.get();
}



A cleaner way to do it is thus:

CODE

#include <iostream>
using namespace std;

int main () {
    cout << "Hello, world!" << endl;
    cout << "Press any key to continue..." << endl;
    cin.get();

    return 0;
}


Note the use of "using namespace std;" under the #include, it means you don't have to to put std:: in front of everything. smile.gif
User is online!Profile CardPM
+Quote Post

Amadeus
RE: Help With Dev C++
5 Jun, 2007 - 04:29 AM
Post #6

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
The use of the std:: scoping operator is actually the preferred manner of coding (although I rarely use it myself smile.gif ).

By using the all encompassing including namespace std;, you are including the entire contents of the namespace, whether you use the elements or not - it actually kind of defeats the purposes of namespaces.
User is offlineProfile CardPM
+Quote Post

MorphiusFaydal
RE: Help With Dev C++
5 Jun, 2007 - 09:30 AM
Post #7

D.I.C Lover
Group Icon

Joined: 12 May, 2005
Posts: 1,104



Thanked: 8 times
Expert In: Hardware, Networking

My Contributions
Heh. I didn't know it was the "preffered manner", I've always just used it.

If you're not using multiple namespaces, then why not just take the shortcut?
User is online!Profile CardPM
+Quote Post

Amadeus
RE: Help With Dev C++
5 Jun, 2007 - 10:19 AM
Post #8

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
You certainly can...no problems at all. i was merely mentioning that from an accepted standards of structure viewpoint, specifying the std:: scoping in front of the methods required is preferred over using the all encompassing using namespace std;

It really has to do with establishing good programming practice, as opposed to multiple practices for different situations.

That being said, if you're only using one namespace, there's nothing stopping you from the all encompassing approach.
User is offlineProfile CardPM
+Quote Post

jollyc
RE: Help With Dev C++
5 Jun, 2007 - 09:31 PM
Post #9

New D.I.C Head
*

Joined: 5 Jun, 2007
Posts: 2


My Contributions
One of the first thing I noticed was the same thing as well. There were a few things I was going to say but as I read the replies I saw most of the things I was going to say (but with reasons why it wasn't doing what you expected). I vaguely know the reasons but that was good to read.

The other thing I tried was go into command prompt (or cmd) and goto the path your exe is in and run that way. It may be the hack way (more than likely) but that's what I did when I wasn't sure if I wanted return(1) or (o).

jolly.things.to.learn
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 10:06PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month