Computer Science Canada Complete Nub question here |
Author: | MrShrimp [ 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? |
Author: | Catalyst [ Sun Jul 04, 2004 2:16 pm ] | ||||
Post subject: | |||||
cout is in the std namespace so u would to either use the namespace which could be done using
or you could use the full name
|
Author: | MrShrimp [ Sun Jul 04, 2004 5:31 pm ] |
Post subject: | |
Thanks alot, ill probably have more really bad questions later. |
Author: | Mazer [ Sun Jul 04, 2004 8:53 pm ] | ||||
Post subject: | |||||
I'm not sure whether that fixed your problem or not but you should remember to either have
|
Author: | Andy [ Sun Jul 04, 2004 11:03 pm ] |
Post subject: | |
if ur not using namespace use #include<iostream.h> |
Author: | wtd [ Mon Jul 05, 2004 1:48 am ] | ||||||
Post subject: | |||||||
In C++, main should always return int.
Not:
Or:
|
Author: | Andy [ Mon Jul 05, 2004 2:01 am ] |
Post subject: | |
whatd wrong with void main()? like i know how ppl say its bad practice... but why tho? |
Author: | wtd [ Mon Jul 05, 2004 1:52 pm ] |
Post 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. |
Author: | Andy [ Mon Jul 05, 2004 4:27 pm ] |
Post subject: | |
but on windows its fine to use void rite? |
Author: | wtd [ Mon Jul 05, 2004 7:44 pm ] |
Post 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". |
Author: | Mazer [ Mon Jul 05, 2004 7:51 pm ] |
Post 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. |
Author: | Andy [ Tue Jul 06, 2004 1:46 am ] |
Post subject: | |
wtd wrote: Then you're technically no longer writing C++ code.
??? i dun get it Mazer wrote: PS share. dun get that either |
Author: | wtd [ Tue Jul 06, 2004 3:10 am ] |
Post 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. |