• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[C++] B-Tutorial Part one (text & user input)

offonline
Loyal Member
Joined
Aug 5, 2009
Messages
1,403
Reaction score
164
Welcome to my first C++ Turtorial!


What is C, What is C++, and What is the Difference?
C is a programming language originally developed for developing the Unix operating system. It is a low-level and powerful language, but it lacks many modern and useful constructs. C++ is a newer language, based on C, that adds many more modern programming language features that make it easier to program than C.

Basically, C++ maintains all aspects of the C language, while providing new features to programmers that make it easier to write useful and sophisticated programs.

For example, C++ makes it easier to manage memory and adds several features to allow "object-oriented" programming and "generic" programming. Basically, it makes it easier for programmers to stop thinking about the nitty-gritty details of how the machine works and think about the problems they are trying to solve.


So, what is C++ used for?

C++ is a powerful general-purpose programming language. It can be used to create small programs or large applications. It can be used to make CGI scripts or console-only DOS programs. C++ allows you to create programs to do almost anything you need to do. The creator of C++, Bjarne Stroustrup, has put together a partial list of applications written in C++.

To program C++ you'll need a complier. A compiler converts source code - the actual instructions typed by the programmer - into an executable file. Numerous compilers are available for C and C++. Listed on the sidebar are several pages with information on specific compilers.
Thanks cplusplus.com for this nice intro

Here's the C++ i would personally suggest.
1. Download Visual Basic 2008
2. Download Eclipse
3. Download Codeblocks
4. Download Codewarrior
5. Download Dev-C++

All these are compliers.


When you've downloaded your complier, you'll need to create a new project. Click
File > New Project
Win32 Console Application [x]
Choose a name for your project.
[Empty project]
Right click on your project, at the left menu bar.
Click Add > New > [C++ file] Click OK.





Lets get started with the coding!

Text input!

PHP:
#include <iostream>  // This is a library you'll need to display text
using namespace std; // Let's you acces your library for c++ .


int main() // This is our main function.
{ // Open bracket. Inside the brackets is where the magic stuff happends.

cout<<" Hello Ragezone" <<endl; // Cout is the function which displays the text and 'endl is EndLine, what it does is jumps down a line. The '' ; '' ends a statment.
cin.get(); // If we would'nt add this it would terminate the program after the text have appear cus the program has nothing left to do
} // End bracket

This is what it will look like when your done [Complie & run]

King Grub - [C++] B-Tutorial Part one (text & user input) - RaGEZONE Forums



Code 2

User input!

PHP:
#include <iostream>

using namespace std;

int main()
{
  int number; // Variable function name

  cout<<"Please enter a number: "; // Number: allows you to type  something into the program
  cin>> number; // The first statement declares a variable of type int called number, and the second one waits for an input from cin (the keyboard) in order to store it in this integer variable.
  cin.ignore(); //this is another function that reads and discards a character

  cout<<"You entered: " <<number <<"\n"; // " <<number <<" shows what number(s) you type'd before. ( \n ) Is another way to jumpdown a line
  cin.get();
}

This is what it will look like when its done [Complie & run]

King Grub - [C++] B-Tutorial Part one (text & user input) - RaGEZONE Forums

This is the end of C++ turtorial part one. The next turtorial i'll write will be about
If statments and loops. Before you read my next guide, practise with this and play around with the codes :) .

Hope you like my turtorial, if you do Thank me if you'd like!

Other turtorials for beginners:
http://www.cprogramming.com/begin.html
http://www.howtoforge.com/beginners_guide_to_cplusplus
http://cpp-tutorial.cpp4u.com/
 
Last edited by a moderator:
Ginger by design.
Loyal Member
Joined
Feb 15, 2007
Messages
2,340
Reaction score
653
Re: [B-Turtorial] C++ Part one (text & user input)

1. Technically C is not a subset of C++. There are features of C which were intentionally left out of the C++ standard for reasons made clear by their use. The generally resulted in difficult to maintain, difficult to read code and were not consistent with the rest of the language. They also added unnecessary complexities to the compiler and coupled with classes and templates would've made C++ compilers far more complex than would be acceptable.

2. The use of 'using' should rarely be used on the entire namespace. You can explicitly write

Code:
using std::cin;
using std::cout;

To gain access to the cin/cout globals you want, or explicitly write them as std::cin and std::cout. It's considered bad style to globally include an entire namespace as it reduces their usefulness (why have namespaces if we dump them all in the global space anyway?).

3. The standard main function prototype is as follows:

Code:
int main(int argc, char** argv);

Most compilers will permit a main function with no parameters and no return value because it's a cdecl call therefore the caller does not need to adjust the stack and the resulting value in eax is random, albeit unuseful as a return value (it may be consistent, however, but it likely won't be meaningful to the end-user).

4. Proper indentation should be practiced. The second example is fine but the first one is not properly indented.

5. When declaring a variable, it's considered good style to declare it immediately before use and then to initialize it with some filler value.

6. iostream is a header file that defines the i/o stream classes and such. It's not a function.

7. "cout" is not a function, more precisely "cout.operator <<(...)" is the function being invoked. cout is an instance of an i/o class defined in the iostream header.

8. The comments given here are largely incorrect or inverted.

Other than that, fairly basic.
 
Last edited:
offonline
Loyal Member
Joined
Aug 5, 2009
Messages
1,403
Reaction score
164
Re: [B-Turtorial] C++ Part one (text & user input)

Alright, thanks for your tips ;0

2. I find using namespace std; easier.
 
Last edited:
Master Summoner
Joined
Jan 11, 2009
Messages
505
Reaction score
8
Re: [B-Turtorial] C++ Part one (text & user input)

finding it easier to use certainly isn't a good excuse! lol :p
 
offonline
Loyal Member
Joined
Aug 5, 2009
Messages
1,403
Reaction score
164
Re: [B-Turtorial] C++ Part one (text & user input)

finding it easier to use certainly isn't a good excuse! lol :p

Lol. I have always done like that, and i'll continue doing it.
:*:
 
Master Summoner
Joined
Jan 11, 2009
Messages
505
Reaction score
8
Re: [B-Turtorial] C++ Part one (text & user input)

you're right, it isn't for your own benefit. but, it is for the users, and in some cases that includes yourself. sometimes it's rather convinient to use correct practice to avoid mess, even little. each individual users has to be taken into consideration along with your full priority upon your program.

just agree and say yes, otherwise other users who will visit this thread might subside with your argument. your poor argument. hehe :p
 
offonline
Loyal Member
Joined
Aug 5, 2009
Messages
1,403
Reaction score
164
Re: [B-Turtorial] C++ Part one (text & user input)

you're right, it isn't for your own benefit. but, it is for the users, and in some cases that includes yourself. sometimes it's rather convinient to use correct practice to avoid mess, even little. each individual users has to be taken into consideration along with your full priority upon your program.

just agree and say yes, otherwise other users who will visit this thread might subside with your argument. your poor argument. hehe :p

Yes i totally agree.
 
Master Summoner
Joined
Jan 11, 2009
Messages
505
Reaction score
8
Re: [B-Turtorial] C++ Part one (text & user input)

oh, by the way, since Merlin merely brought up that little note relative to command line parameters, you might as well add that little something about command line parameters. :p
 
HAARP
Joined
Dec 3, 2006
Messages
632
Reaction score
109
Re: [B-Turtorial] C++ Part one (text & user input)

nice but shouldn't you learn the language before you teach it?

Just asking..
 
offonline
Loyal Member
Joined
Aug 5, 2009
Messages
1,403
Reaction score
164
Re: [B-Turtorial] C++ Part one (text & user input)

nice but shouldn't you learn the language before you teach it?

Just asking..

I already know the basics of c++, thats why i make a turtorial.
Should'nt you know poop before speak?
Just asking...
 
Junior Spellweaver
Joined
May 14, 2008
Messages
161
Reaction score
65
Re: [B-Turtorial] C++ Part one (text & user input)

i dont mean to criticize, but you should have explained your variable part. i am currently taking a c++ class, and i believe that if you want to go to IF statements, you should know about int's. all yours showed was an int statement, did not say what it was, what it did, how you can customize, nor how it relates to CIN and IF/Else statements.
and the format of the script like how the curly braces are used. if you are beginning C++ you will not know that {} holds a code. basic things you thing are simple and people can figure out on their own should still be taught.
Btw i recommend CodeWarrior and Dev-C++
code warrior is a fairly good compiler and devC++ is very simple and pretty user friendly.
my school uses code warrior
 
Last edited:
offonline
Loyal Member
Joined
Aug 5, 2009
Messages
1,403
Reaction score
164
Re: [B-Turtorial] C++ Part one (text & user input)

i dont mean to criticize, but you should have explained your variable part. i am currently taking a c++ class, and i believe that if you want to go to IF statements, you should know about int's. all yours showed was an int statement, did not say what it was, what it did, how you can customize, nor how it relates to CIN and IF/Else statements.
and the format of the script like how the curly braces are used. if you are beginning C++ you will not know that {} holds a code. basic things you thing are simple and people can figure out on their own should still be taught.
Btw i recommend CodeWarrior and Dev-C++
code warrior is a fairly good compiler and devC++ is very simple and pretty user friendly.
my school uses code warrior

Thank you for the non criticize-ment :p.
Honestly, i appreciate it. I'll update this thread when i've got home or tomorrow. I'll talk more about variables and show more examples. Dev-c++ is really good :).
 
Newbie Spellweaver
Joined
Dec 6, 2009
Messages
12
Reaction score
0
Re: [B-Turtorial] C++ Part one (text & user input)

Wow, Nice, Looking forward to the next ones !
 
Ginger by design.
Loyal Member
Joined
Feb 15, 2007
Messages
2,340
Reaction score
653
Re: [B-Turtorial] C++ Part one (text & user input)

Thanks :)



I find Dev-c++ pretty beginner friendly and easy to use.
Never tried CW thought.

Easy to use yes. Lacking a lot of features that are good for beginners though. And with no decent debugger support, that's just fail. Debugging is one of the most important things you should be able to do.
 
offonline
Loyal Member
Joined
Aug 5, 2009
Messages
1,403
Reaction score
164
Re: [B-Turtorial] C++ Part one (text & user input)

Easy to use yes. Lacking a lot of features that are good for beginners though. And with no decent debugger support, that's just fail. Debugging is one of the most important things you should be able to do.

Yea your right, but i'll still add it.
Which one do you suggest? :rolleyes:
 
HAARP
Joined
Dec 3, 2006
Messages
632
Reaction score
109
Re: [B-Turtorial] C++ Part one (text & user input)

I already know the basics of c++, thats why i make a turtorial.
Should'nt you know poop before speak?
Just asking...

Then why do you recommend Visual Basic as your #1 option to compile c++ code?
That recommendation alone is enough to confuse 90% of beginners who read this and haven't read anything about c++ before.

Also in your first example
#include <iostream> // This is a function you'll need to display text
that's not a function.. it's a library

and in your second example why do you use both cin.get() and cin.ignore() functions at the same time.. one should be enough

and I know my poop and I know that if I had followed this tutorial and learnt your examples by heart instead or going directly to some site that actually explains poop properly my definitions of what stuff is would be pretty flawed by now
 
offonline
Loyal Member
Joined
Aug 5, 2009
Messages
1,403
Reaction score
164
Re: [B-Turtorial] C++ Part one (text & user input)

Then why do you recommend Visual Basic as your #1 option to compile c++ code?
That recommendation alone is enough to confuse 90% of beginners who read this and haven't read anything about c++ before.

Also in your first example
#include <iostream> // This is a function you'll need to display text
that's not a function.. it's a library

and in your second example why do you use both cin.get() and cin.ignore() functions at the same time.. one should be enough

and I know my poop and I know that if I had followed this tutorial and learnt your examples by heart instead or going directly to some site that actually explains poop properly my definitions of what stuff is would be pretty flawed by now

If they decide to learn C++ i'm pretty Ducking sure they'll need some brain so they atleast could use Visual Basic.
Everyone do mistakes, i'd know the basics but i'm not a master with C++.
 
Junior Spellweaver
Joined
May 14, 2008
Messages
161
Reaction score
65
Re: [B-Turtorial] C++ Part one (text & user input)

Thank you for the non criticize-ment :p.
Honestly, i appreciate it. I'll update this thread when i've got home or tomorrow. I'll talk more about variables and show more examples. Dev-c++ is really good :).
Yea, sometimes people needmore simple things than other complicated apps
Also, you should include a reference section to many c++ sites like cplusplus.com to help people.
 
Back
Top