Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Complete Nub question here
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MrShrimp




PostPosted: Sun Jul 04, 2004 1:49 pm   Post subject: Complete Nub question here

Saw a similiar post but didnt answer my question, so sorry for making you guys say some stuff over again but here goes...

Im using dev-C++ and for some reason i cant include iostream properly. I end up including iostream.h which includes iostream in it but then it says something like cout undeclared or something everytime i use it.

This is what i have now that gives me `cout' undeclared

#include <iostream>

main ()
{
cout <<"Hi";
}

Do I have to save it to a certain place or something?
Sponsor
Sponsor
Sponsor
sponsor
Catalyst




PostPosted: Sun Jul 04, 2004 2:16 pm   Post subject: (No subject)

cout is in the std namespace

so u would to either use the namespace which could be done using
code:

using namespace std;
at the top of ur code

or you could use the full name
code:

 std::cout <<"Hi";
MrShrimp




PostPosted: Sun Jul 04, 2004 5:31 pm   Post subject: (No subject)

Thanks alot, ill probably have more really bad questions later.
Mazer




PostPosted: Sun Jul 04, 2004 8:53 pm   Post subject: (No subject)

I'm not sure whether that fixed your problem or not but you should remember to either have

code:

void main ()
{
cout <<"Hi";
}


code:

int main ()
{
cout <<"Hi";
return 0;
}
Andy




PostPosted: Sun Jul 04, 2004 11:03 pm   Post subject: (No subject)

if ur not using namespace use #include<iostream.h>
wtd




PostPosted: Mon Jul 05, 2004 1:48 am   Post subject: (No subject)

In C++, main should always return int.

code:
int main()
{

}


Not:

code:
main()
{

}


Or:

code:
void main()
{

}
Andy




PostPosted: Mon Jul 05, 2004 2:01 am   Post subject: (No subject)

whatd wrong with void main()?

like i know how ppl say its bad practice... but why tho?
wtd




PostPosted: Mon Jul 05, 2004 1:52 pm   Post subject: (No subject)

According to the C++ standard, "main" should always return an integer value. The reasoning is that that is the lowest common denominator way for a program to indicate failure or success to the operating system. On POSIX compliant systems this means 0 is success and failure is anything else.

Not returning a value causes all kinds of havoc. The computer, having not gotten any output from the program about how things went, will assign an essentially random number. That way lies madness.
Andy




PostPosted: Mon Jul 05, 2004 4:27 pm   Post subject: (No subject)

but on windows its fine to use void rite?
wtd




PostPosted: Mon Jul 05, 2004 7:44 pm   Post subject: (No subject)

dodge_tomahawk wrote:
but on windows its fine to use void rite?


Then you're technically no longer writing C++ code.

Just stick to the spec, and you won't have to worry about running into problems with compilers. Besides, "int" is easier to type than "void".
Mazer




PostPosted: Mon Jul 05, 2004 7:51 pm   Post subject: (No subject)

And if you've got time to search all over the net for nude pics of Hyori, you've got enough time to type "return 0;" at the end.

PS share.
Andy




PostPosted: Tue Jul 06, 2004 1:46 am   Post subject: (No subject)

wtd wrote:
Then you're technically no longer writing C++ code.

??? i dun get it

Mazer wrote:
PS share.
dun get that either
wtd




PostPosted: Tue Jul 06, 2004 3:10 am   Post subject: (No subject)

dodge_tomahawk wrote:
wtd wrote:
Then you're technically no longer writing C++ code.

??? i dun get it


There is an agreed upon standard for what C++ is. That standard dictates that main should return an int. If you return void, or don't give it a return type, then you've deviated from the standard.

The danger in that is that you can no longer count on your program behaving as laid out in the standard.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: