Post: Basic C++ Programming
06-20-2012, 04:43 AM #1
(adsbygoogle = window.adsbygoogle || []).push({}); Now I thought I'd help a few users out with basic C++ programming. I am still learning my self, but I'm getting more advanced.

Includes:
Includes basically reference items, dll's, and other programs. It incoorperates codes into your program, and it's helps usage. This can be easily done by the following code:
    
#include <object_name>


The object name usually ends with a ".h" but it can be a program or dll. This is placed before your main code.

Input and Output:
For this example we will be using the namespace std, and using the iostream. This makes it possible to use cout, cin, and endl.

(note: you always start your program with int main() (to have the program complete it will always return with 0 (what I learned from C++ studies)))

    
#include <iostream>

using namespace std;

int main()
{
cout << "Hello world.. \n";
}


Now what that is doing is printing hello work into console. cout is like print in C#. cout stands for console out. It is output. << is the bit movement. and the text output is Hello world... (\n is newline in program language)

but that will close console right away.. so we need to add a
    
cin.get();


this will require the user to press enter, before the program closes. Add it right after the cout call..

Now lets move onto user input

User input is just as easy as output but it's set up a little different :p

continued from our above code...

    
int main()
{
int age_here
cout << "please enter your age";
cin >> age_here;
cin.ignore(); //this causes to skip the user requiring to press enter...
cout << "You entered an age of" << age_here << "!\n";
cin.get();
return 0;
}


by using cin >> variable we are setting up user input to input data (such as a name, age, date, or whatever.). cin.ignore() skips the user needing to press enter (basically in continues the code). Then we output what the user entered. and then the program pauses with cin.get();

for strings you can use...

    
char string[number here];

cout<<"Enter your name.";
cin.getline (string, number here, '\n'Winky Winky;
cout<<"Your name is: "<<string<<endl;
cin.get();


Conclusion:
I hoped you learned something from this because I like teaching people new things. I am still learning myself so :p

Next tutorial I might do an if then statement, for loops, while loops, do while loops, structures, pointers, or variables. I don't know yet, but I hope maybe users can request things. Smile
Last edited by Jakes625 ; 06-20-2012 at 06:19 AM.

The following 4 users say thank you to Jakes625 for this useful post:

Davey, DinoFreak, Ninja, TheFuziioN-
06-20-2012, 11:35 PM #2
Davey
PC Master Race
Nice Gamer Winky Winky
06-20-2012, 11:35 PM #3
Winning
Former Staff
I learned that I don't want to learn C++, but thanks for making a great beginners tutorial for others.

The following 3 users say thank you to Winning for this useful post:

Pichu, River J
06-21-2012, 03:47 AM #4
Pichu
RIP PICHU.
Originally posted by Winning View Post
I learned that I don't want to learn C++, but thanks for making a great beginners tutorial for others.


C# is starting to replace C++ although if you are going into game programming C++ is still the way to go.

C# already has system management built in whereas you have to program and manage the system and how it handles pretty much yourself, (Well it still is managed but to a point.)

As C# becomes older, it is becoming more and more powerful. It's the reason why if you take computer science in college, they teach you C# and C++, (Well mine gives the option C# or VB.Net as both are the same thing just different syntax but C# being closer to C++).

Application wise, C# is starting to become the way to go. Software wise, C++ because you can manage it and make it faster as well as the fact that you are not just .Net limited.
06-21-2012, 06:04 AM #5
Originally posted by Pichu View Post
C# is starting to replace C++ although if you are going into game programming C++ is still the way to go.

C# already has system management built in whereas you have to program and manage the system and how it handles pretty much yourself, (Well it still is managed but to a point.)

As C# becomes older, it is becoming more and more powerful. It's the reason why if you take computer science in college, they teach you C# and C++, (Well mine gives the option C# or VB.Net as both are the same thing just different syntax but C# being closer to C++).

Application wise, C# is starting to become the way to go. Software wise, C++ because you can manage it and make it faster as well as the fact that you are not just .Net limited.



Yeah, I thought learning C++ would be a good way to go though. You can manage data easier, but it is also a way bigger pain in the ass to program. Basic fundamentals you take for granted in C# or vb.net such as (pointers, and function placing) is completely different. You have to define a variable always before you use it instead of having it created when it's first called :p and all the functions have to go before the program starts... etc. :p
06-21-2012, 06:15 AM #6
xGscClan
Bounty hunter
Originally posted by GAMER View Post
Now I thought I'd help a few users out with basic C++ programming. I am still learning my self, but I'm getting more advanced.

Includes:
Includes basically reference items, dll's, and other programs. It incoorperates codes into your program, and it's helps usage. This can be easily done by the following code:
    
#include <object_name>


The object name usually ends with a ".h" but it can be a program or dll. This is placed before your main code.

Input and Output:
For this example we will be using the namespace std, and using the iostream. This makes it possible to use cout, cin, and endl.

(note: you always start your program with int main() (to have the program complete it will always return with 0 (what I learned from C++ studies)))

    
#include <iostream>

using namespace std;

int main()
{
cout << "Hello world.. \n";
}


Now what that is doing is printing hello work into console. cout is like print in C#. cout stands for console out. It is output. << is the bit movement. and the text output is Hello world... (\n is newline in program language)

but that will close console right away.. so we need to add a
    
cin.get();


this will require the user to press enter, before the program closes. Add it right after the cout call..

Now lets move onto user input

User input is just as easy as output but it's set up a little different :p

continued from our above code...

    
int main()
{
int age_here
cout << "please enter your age";
cin >> age_here;
cin.ignore(); //this causes to skip the user requiring to press enter...
cout << "You entered an age of" << age_here << "!\n";
cin.get();
return 0;
}


by using cin >> variable we are setting up user input to input data (such as a name, age, date, or whatever.). cin.ignore() skips the user needing to press enter (basically in continues the code). Then we output what the user entered. and then the program pauses with cin.get();

for strings you can use...

    
char string[number here];

cout<<"Enter your name.";
cin.getline (string, number here, '\n'Winky Winky;
cout<<"Your name is: "<<string<<endl;
cin.get();


Conclusion:
I hoped you learned something from this because I like teaching people new things. I am still learning myself so :p

Next tutorial I might do an if then statement, for loops, while loops, do while loops, structures, pointers, or variables. I don't know yet, but I hope maybe users can request things. Smile


You should make a code that lags the game out. When im hosting and i end game everyone cries and dislikes my vids on youtube becuse i gave them menu then ended the game but if it lags people dont care they are just like " it lagged , ahh shit happens"
06-21-2012, 06:35 AM #7
Kellis
LoanWolf
:wtf: teh fuuq?
06-21-2012, 05:17 PM #8
Pichu
RIP PICHU.
Originally posted by GAMER View Post
Yeah, I thought learning C++ would be a good way to go though. You can manage data easier, but it is also a way bigger pain in the ass to program. Basic fundamentals you take for granted in C# or vb.net such as (pointers, and function placing) is completely different. You have to define a variable always before you use it instead of having it created when it's first called :p and all the functions have to go before the program starts... etc. :p


Kinda the reason why I probably won't learn C++ for hobby programming. I probably will learn Java since I want have fun and make person private servers/modify Minecraft.

The following user thanked Pichu for this useful post:

06-21-2012, 10:21 PM #9
lBryzla
Do a barrel roll!
Really nice tut, good job man!
06-22-2012, 07:39 PM #10
Pichu
RIP PICHU.
Originally posted by ImWelch View Post
:wtf: teh fuuq?


If you have prior knowledge of basic programming, you would somewhat understand. Yea, it looks hard but once you start learning it from the basics, you can understand it.

The following user thanked Pichu for this useful post:

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo