Page 2 of 3

Posted: Tue May 18, 2004 2:15 am
by Robomaniac
int main()

Posted: Tue May 18, 2004 2:20 am
by Phreak

Code: Select all

#include <stdin.h>
main()
{
    printf("Hello World\n");
}
I don't think stdin.h is a valid header file. What you want is stdioh, which has printf defined in it.

Phreak

Posted: Tue May 18, 2004 3:04 am
by Unarekin
Robomaniac wrote:int main()
No, void main(). He isn't returning a value. If he were to put int main(), he would need to have, say, 'return 0;' at the end.

Posted: Tue May 18, 2004 5:54 am
by c_olin3404
Just a warning.... If you are going to learn c++, give it your all! Don't skip any chapters! And don't expect results too fast.

I did all of these things, and I was discouraged a bit... but now... 2 years later, I have learned so much, and the possibilities of C++ are endless. It is very rewarding and very fun.

Good luck man!

ps, a good site with some nice forums for c/c++ is www.cprogramming.com

Posted: Tue May 18, 2004 6:35 am
by Tyn
c_olin3404 wrote:Just a warning.... If you are going to learn c++, give it your all! Don't skip any chapters! And don't expect results too fast.

I did all of these things, and I was discouraged a bit... but now... 2 years later, I have learned so much, and the possibilities of C++ are endless. It is very rewarding and very fun.

Good luck man!

ps, a good site with some nice forums for c/c++ is www.cprogramming.com
My advice would be to read it cover to cover first time, don't worry if it goes over your head a little because you can then jump to certain chapters once you know the way around the book. Don't expect to read it once and then just know C++, it's too complicated to do that. I still reference to a few C++ books my bro has when I'm in trouble.

Posted: Tue May 18, 2004 10:32 am
by warui
Unarekin wrote:
Robomaniac wrote:int main()
No, void main(). He isn't returning a value. If he were to put int main(), he would need to have, say, 'return 0;' at the end.
No, void main() is not a standard. Some compilers alows it, but official ANSI C++ standard forbids it.

And AFAIR you can define function w return type other then void and still don't use return in it's body. Some compilers will only give you warning about this. And others won't even warn you ;)

Posted: Tue May 18, 2004 10:50 am
by Coolkat
it's not #include <stdin.h> it's #include <stdio.h> and for C++ you don't need the .h at the end..

#include <iostream>

will work and is what is standard.

and what is so bad about sticking alittle return 0; at the end of a function?

Posted: Tue May 18, 2004 12:36 pm
by Phreak
Coolkat, all of those things have been covered. Also, I overlooked the main() return value, since I am used to a C compiler which doesn't require you to define the integer return value of the main function.

Phreak

Posted: Tue May 18, 2004 4:01 pm
by warui
Coolkat wrote:it's not #include <stdin.h> it's #include <stdio.h> and for C++ you don't need the .h at the end..
Only for old c++ headers, for most (or even all, i don't remeber) c header we add "c" in the begining and drop ".h". So "stdio.h" changes into "cstdio".

Posted: Tue May 18, 2004 5:43 pm
by Unarekin
warui wrote:
Unarekin wrote:
Robomaniac wrote:int main()
No, void main(). He isn't returning a value. If he were to put int main(), he would need to have, say, 'return 0;' at the end.
No, void main() is not a standard. Some compilers alows it, but official ANSI C++ standard forbids it.

And AFAIR you can define function w return type other then void and still don't use return in it's body. Some compilers will only give you warning about this. And others won't even warn you ;)
It's bad form to define a return type and not return anything. ;)
Coolkat wrote:and what is so bad about sticking alittle return 0; at the end of a function?
Never said anything was bad about it, just that the return value was never specified. :)

Posted: Tue May 18, 2004 9:25 pm
by Robomaniac
Dev C++ borks on void main if i remember, i just use int main and add a return 0;

or if i feel like it

bool main

return true;

:P

just whatever i feel

@duomaxwl -> Aim me if your having a little trouble, i can help you with some small stuff, however, i will not teach you everything you need, just if you need some help

Posted: Tue May 18, 2004 11:18 pm
by Tyn
Also, it isn't bad form for the main function to have a return value of nothing, it's actually the standard. It's bad form to have void main() although most compilers allow it.

Posted: Wed May 19, 2004 1:15 am
by Unarekin
Tyn wrote:Also, it isn't bad form for the main function to have a return value of nothing, it's actually the standard. It's bad form to have void main() although most compilers allow it.
I hope you aren't misunderstanding me: I meant to say it's bad form to declare a return type for a function, then not return anything. Then again, I rarely rarely rarely write a function without it returning something.

Posted: Wed May 19, 2004 11:33 pm
by duomaxwl
#include <stdio.h>
int main()
{
printf("Hello World\n");

return 0;
}

hehe... someone tell me whats wrong with this? please...

Posted: Thu May 20, 2004 12:15 am
by Robomaniac
Nothing should be, what errors do you get?