Archived

This topic is now archived and is closed to further replies.

TotalCoder

Any C++ newbie or wants to learn pls read

Recommended Posts

Hi, Anyone interested in learning C++ please take a look at my tutorial and let me know what more I can change or add so that it better targets the novice. This tutorial is geared towards the complete novice and shows them how to get Borland C++ 5.5 up and running on the Windows platform. I would really appreciate your feedback. Please goto http://www.totalcoder.com and look at the Borland C++ 5.5 tutorial, and either post your comments and/or suggestions here or on the site. Sam ----- TotalCoder http://www.totalcoder.com "Resources, tutorials, and articles for the novice, part-time, and hobbyist programmer"

Share this post


Link to post
Share on other sites
You have a typo on your #include line (the less than and greater than). Use < and > for less than and greater than symbols, respectively. C++ compliance issues: You should be including iostream, not iostream.h; you should also use std::cout instead of cout if you do that (or put "using namespace std" in there somewhere). Somehow I doubt you should debate whether C or C++ is better in a compiler related tutorial, but to each his own I guess.

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites
Hi Sam,
Nice one. The tutorial is OK so far. One thing I''d suggest is a few screen shots of what you should actually see as you''re going through the process. I know it might sound a bit mickey mouse, but when youre just getting started youre very unsure of yourself...
Jon

Share this post


Link to post
Share on other sites
Thanks let me make those revisions, and the screen shot ideal is a good one. I forgot about the C++ compliance issues, since Visual C++ breaks a lot of them. They always include #include it made me forget it is #include .

Also with C++ header files should be named with .hpp extension. Let me get a rewrite and I''ll repost, did you find it helpful for the newbies?



Sam
-----
TotalCoder
http://www.totalcoder.com
"Resources, tutorials, and articles for the novice, part-time, and hobbyist programmer"

Share this post


Link to post
Share on other sites
Null and Void,

I was trying not to debate whether C or C++ is better, I''m sorry it came off that way. I was merely trying to inform the reader on why I was using C++, but if it may be confusing for the newbie I''ll remove it.

Sam
-----
TotalCoder
http://www.totalcoder.com
"Resources, tutorials, and articles for the novice, part-time, and hobbyist programmer"

Share this post


Link to post
Share on other sites
Well for an explanation on why void main... is improper here is a direct quote from Bjarne on his site. Also, I am busily incorporating these changes and everything else into the first tutorial. Thanks again everyone!

quote:

Can I write "void main()"?
The definition
void main() { /* ... */ }

is not and never has been C++, nor has it even been C. See the ISO C++ standard 3.6.1[2] or the ISO C standard 5.1.2.2.1. A conforming implementation accepts
int main() { /* ... */ }

and
int main(int argc, char* argv[]) { /* ... */ }

A conforming implementation may provide more versions of main(), but they must all have return type int. The int returned by main() is a way for a program to return a value to "the system" that invokes it. On systems that doesn''t provide such a facility the return value is ignored, but that doesn''t make "void main()" legal C++ or legal C. Even if your compiler accepts "void main()" avoid it, or risk being considered ignorant by C and C++ programmers.
In C++ main() need not contain an explicit return statement. In that case, the value returned is 0, meaning successful execution. For example:

#include

int main()
{
std::cout << "This program returns the integer value 0\n";
}

Note also that neither ISO C++ nor C99 allows you to leave the type out of a declation. That is, in contrast to C89 and ARM C++ ,"int" is not assumed where a type is missing in a declaration. Consequently:
#include

main() { /* ... */ }

is an error because the return type of main() is missing.



Sam
-----
TotalCoder
http://www.totalcoder.com
"Resources, tutorials, and articles for the novice, part-time, and hobbyist programmer"

Share this post


Link to post
Share on other sites
I''ll give it a try, do you have a link? If not, I''ll pull it down from Google. But thanks for the information, that is what I''m looking for, before Borland, all I new was LCC, GCC, Borland, and, for work, I use MS Visual C++.

But since I''m targeting novices and hobbyist I don''t want to include VC++ from the beginning because most non-students can''t afford it. But I''ll look into Dev C++, does it have a color syntaxing IDE? I hate coding in Notepad because I don''t remember half the keywords! MS Visual C++ has spoiled me and it looks as if it has hidden many important constructs from me as well such as int main() etc... Since coding in C++ and using MFC I haven''t seen a MAIN function in eons.

Sam
-----
TotalCoder
http://www.totalcoder.com
"Resources, tutorials, and articles for the novice, part-time, and hobbyist programmer"

Share this post


Link to post
Share on other sites
I personally use void to indicate an empty parameter list in C++ too, I think it makes it more clear (maybe because I do a whole lot of C programming too?).
quote:
Original post by TotalCoder
I''ll give it a try, do you have a link?

Bloodshed.net.
quote:
Original post by TotalCoder
But I''ll look into Dev C++, does it have a color syntaxing IDE?

Yes. It''s a lot like MSVC.

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites
quote:
Original post by krez
you mean
int SomeFunc(void) { ... };  

right?
why not? i thought that was good form...


I dont recommend it - ergo its not recommended.



Fantastic doctrines (like Christianity or Islam or Marxism) require unanimity of belief. One dissenter casts doubt on the creed of millions. Thus the fear and hate; thus the torture chamber, the iron stake, the gallows, the labor camp, the psychiatric ward - Edward Abbey

Share this post


Link to post
Share on other sites
Null - nope. The standard explicitly states that if you exit main without returning a value, the effect will be that of returning 0.

(VC++ 6.0 doesnt work that way, tho)

Fantastic doctrines (like Christianity or Islam or Marxism) require unanimity of belief. One dissenter casts doubt on the creed of millions. Thus the fear and hate; thus the torture chamber, the iron stake, the gallows, the labor camp, the psychiatric ward - Edward Abbey

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Arild Fines
I dont recommend it - ergo its not recommended.


yes, i figured that out the first time you said "it''s not recommended"... but, what i meant to ask was: is there a reason for this, or is it a personal taste thing?

Share this post


Link to post
Share on other sites
Sure there is a reason for it: I dont do it this way, and everybody should do things exactly the same way I do them.

Fantastic doctrines (like Christianity or Islam or Marxism) require unanimity of belief. One dissenter casts doubt on the creed of millions. Thus the fear and hate; thus the torture chamber, the iron stake, the gallows, the labor camp, the psychiatric ward - Edward Abbey

Share this post


Link to post
Share on other sites
Thanks everyone for all your posts, critique, and recommendation. I appreciate everything that you have written. I have included everyone that has contributed to the tutorial in the additional credit section of the article, if any of you want your email or other names attached to it, let me know.

I''m working on the next tutorial which will combine input and outpout mostly cin and cout so that the reader can do some interactive stuff.



Sam
-----
TotalCoder
http://www.totalcoder.com
"Resources, tutorials, and articles for the novice, part-time, and hobbyist programmer"

Share this post


Link to post
Share on other sites
Should there be a return 0 statement? Here is a quote from the Bjarne Style FAQ I found on the web.

quote:

In C++ main() need not contain an explicit return statement. In that case, the value returned is 0, meaning successful execution...



The return value is impled and 0 is returned.

Sam
-----
TotalCoder
http://www.totalcoder.com
"Resources, tutorials, and articles for the novice, part-time, and hobbyist programmer"

Share this post


Link to post
Share on other sites
Bjarne is absolutely correct, as I have pointed out earlier in this thread. Read the standard regarding the main function, section 3.6.2, I think(something like that, anyway - I dont have it here right now).
The main problem is that VC++ gives you a warning when exiting main without an explicit return statement, and since VC++ is the compiler ''everyone'' uses, people think this is they way its supposed to be.

Fantastic doctrines (like Christianity or Islam or Marxism or Microsoft-bashing) require unanimity of belief. One dissenter casts doubt on the creed of millions. Thus the fear and hate; thus the torture chamber, the iron stake, the gallows, the labor camp, the psychiatric ward - Edward Abbey

Share this post


Link to post
Share on other sites