PDA

View Full Version : Learning C++



Riffe
12-27-2008, 01:25 PM
Learning C++



HELLO.cpp - Your first C++ program

In the traditional programming books they start with the word Hello World ( or anything similar ) writes on the screen. We are in this old tradition on.


Write your first direct in the editor, exactly as below. When you controll that it is right register save the file, compile, links and start it. Order Hello World is going to write on the screen. Don't worry about how it works, it was just an exemple so you can known you with development. We will go through the program carefully coming days. Line a List 1.1, enter as:



#include <iostream.h>

List 1.1. HELLO.cpp, the program Hello World.


http://i44.tinypic.com/izm3dh.jpg


Be sure to enter it exactly as it appears. Be particularly careful with spaces and special characters. On line 5 is << which consists of two <characters, which sits at the bottom left of most keyboards. Row 5 ends with a semicolon, do not forget to write it!



http://i44.tinypic.com/izm3dh.jpg

When you run the program HELLO.exe to be Hello World! written on the screen. In that case, congratulations! You just compile and run your first C++ program. It may not look much out of the world, but almost all professional-C++ programmers started with this program.




EDIT: You can't do this on Scar, you need a C++ compiler!

NCDS
12-27-2008, 02:35 PM
Nice little tut :p

Ive been thinking about getting into C++ but havent gotten around to it yet, maybe soon tho!

Riffe
12-27-2008, 05:25 PM
Nice little tut :p

Ive been thinking about getting into C++ but havent gotten around to it yet, maybe soon tho!



Thanks bro:)

Craig`
12-27-2008, 06:29 PM
Good tut, just use Code::Blocks or another IDE for it next time, not scar/++.

boberman
12-27-2008, 10:40 PM
Good tut, just use Code::Blocks or another IDE for it next time, not scar/++.

scar++ != Scar or and IDE. (In fact, if you read the origional post, he said explicitly that you can't use scar)

Scar++ is a library, who's goal is to bring scar functions to c++. It requires a c++ compiler to compiler the code written. (unless the code is already compiled that is)

mastaraymond
12-28-2008, 10:23 AM
http://newdata.box.sk/bx/c/htm/ch01.htm#Heading19

You sure you want to post that without any credits?

Riffe
12-28-2008, 10:25 AM
http://newdata.box.sk/bx/c/htm/ch01.htm#Heading19

You sure you want to post that without any credits?


I promise, belive me.

Craig`
12-28-2008, 11:13 AM
Bob; I know, I just never saw the thing stating you could not use it on scar.

And btw, .h files are not used much now, (unless windows.h).

Use #include <iostream>

using namespace std;

Or:

For every member of the std use std:: in front of it.

std::cout << "Hai"; etc

Yakman
12-28-2008, 10:56 PM
And btw, .h files are not used much now, (unless windows.h).


what if you want to compile parts of your program seperatly

i.e.
myclass.h contains the class definition and prototypes

myclass.cpp contains the actual methods for the class


you compile myclass.cpp and can use myclass.h in other source files.

boberman
12-28-2008, 11:45 PM
what if you want to compile parts of your program seperatly

i.e.
myclass.h contains the class definition and prototypes

myclass.cpp contains the actual methods for the class


you compile myclass.cpp and can use myclass.h in other source files.

I believe he was refering to the fact that .h isn't used as the header ending as much. This is semi-true. iostream should be included as #include <iostream> and not #include <iostream.h>. A few of the standards are like that, specifically the STL.

The thing is, many c/c++ programmers still prefer to use the .h (known as the golden standard) extension. So to say that it is unused would be a stretch.

Either way, it isn't THAT big of a deal. Yes, for the STL you shouldn't have the .h there, however if you are making you're own library or program then it doesn't really matter what the extension is, just as long as you are consistent. (The Boost libraries, libraries who's goal is to one day become part of the STL, use .hpp as their standard header extension)

Ruroken
01-14-2009, 01:07 PM
I call plagiarism. (http://books.google.ca/books?id=Qs-6bP_4etUC&pg=PA17&lpg=PA17&dq=HELLO.cpp+-+Your+first+C%2B%2B+program&source=bl&ots=Rohe1wnkr1&sig=dB_N9Mae5RI12kCrR2Bwhrqpmjo&hl=en&sa=X&oi=book_result&resnum=1&ct=result#PPA17,M1)

mastaraymond
01-14-2009, 01:52 PM
I call plagiarism. (http://books.google.ca/books?id=Qs-6bP_4etUC&pg=PA17&lpg=PA17&dq=HELLO.cpp+-+Your+first+C%2B%2B+program&source=bl&ots=Rohe1wnkr1&sig=dB_N9Mae5RI12kCrR2Bwhrqpmjo&hl=en&sa=X&oi=book_result&resnum=1&ct=result#PPA17,M1)
So did I, but somehow an admin disagreed and removed the infraction.