Author Topic: {C++} Basic tutorial (part 2) <iostream>  (Read 3784 times)

0 Members and 1 Guest are viewing this topic.

[TKC]Symantic

  • The Indifferent Character
  • The Central Committee
  • Heckler
  • *
  • Posts: 1647
  • I can has personal text?
    • View Profile
{C++} Basic tutorial (part 2) <iostream>
« on: December 31, 2008, 12:40:49 am »
in the first part of the series I'm writing we made a program that displays "Hello world" to the screen.

in this part we will go further into the BASIC use of the iostream class (iostream inherits all members from istream and ostream{input and output streams} so instead of including both istream and ostream we can just include iostream.

OK, lets use this as our blank from dev c++

Code: [Select]
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    system("PAUSE");
    return EXIT_SUCCESS;
}

before we just printed something to the screen using the ostream part of the iostream class, now lets look at getting input to our application, in this case we will be taking input from the keyboard and sending it to the screen using cin.
we use cout (look at it, c-out) for output and now cin (c-in) for input, simple enough not to mix em up.

ok, first we need to declare a variable, well first we need to think at what we want, do we want to input numbers, characters,files,string or one of the many other data types? lets try string, so we need to declare our variable as a string.

there are many many ways to declare a variable and initiliaze it we wont worry about the many ways to do something because this is a basic tutorial remember?

the way i set up variables is i define what data type it is (in this case its a string) and then the variable name, in this case we are going to call the variable stuff. you can call it whatever you please (with the exception of pre-defined variable names, but again it a basic tutorial. if you want to learn all that good stuff attend a school.

i define all my variables below "using namespace std;" and above "int main(int argc, char *argv[])" just because thats how i do it.

our code to define the variable stuff to use the data type string will be
Code: [Select]
string stuff;
i could have just told you to copy that in, but i want you to know why we are doing what we are doing.

OK, so this is what my code is looking like.

Code: [Select]
#include <cstdlib>
#include <iostream>

using namespace std;

string stuff;
int main(int argc, char *argv[])
{

    system("PAUSE");
    return EXIT_SUCCESS;
}
ok, now we are going back into main (between the { and the }),now we need to get input to that variable using the keyboard, this is where we use cin.

remember when i said the double carrots (<< >>) define which way the information is sent? we need to take from the keyboard and send to the variable.
Code: [Select]
cin >> stuff;
think of cin as the keyboard for now, so the carrots are pointing to stuff from the keyboard.

now we want to display on the screen what we typed in to make sure its working.

Code: [Select]
cout<<stuff;
that will send stuff to the screen

there is something called endl; (end line), that way it breaks a line instead of saying "press enter to continue" on the same line stuff is being displayed on. think of endl; as the return key in a text file.

the finished code

Code: [Select]
#include <cstdlib>
#include <iostream>

using namespace std;

string stuff;
int main(int argc, char *argv[])
{
 cin >> stuff;
 cout<<stuff<<endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}

-Symantic
« Last Edit: January 09, 2009, 12:04:08 pm by [TKC]Symantic »
Enjoy your creative game-play, whatever that may include.

Subsky

  • Insane Joker
  • ****
  • Posts: 504
  • Subskii
    • View Profile
Re: {C++} Basic tutorial (part 2) <iostream>
« Reply #1 on: January 05, 2009, 07:05:51 am »
Nice tutorial Sym, although I do believe basic C++ is beyond the intellectual capacity of most people here.

What are you thoughts on the language by the way?

M. O.

  • Administrator
  • MasstKer
  • *
  • Posts: 9185
    • View Profile
    • http://www.tkc-community.net
Re: {C++} Basic tutorial (part 2) <iostream>
« Reply #2 on: January 05, 2009, 01:25:44 pm »
Nice tutorial. Good and clear structure.

But I'm more used to #include <string>

Nice tutorial Sym, although I do believe basic C++ is beyond the intellectual capacity of most people here.

What are you thoughts on the language by the way?

Lol what a besser-wisser attitude.  :icon_laugh

Sure C++ is harder than many things, but if people can speak, they can learn c++ too, it's just a question of time.
Heckling is an art, and game hacking a science.

Subsky

  • Insane Joker
  • ****
  • Posts: 504
  • Subskii
    • View Profile
Re: {C++} Basic tutorial (part 2) <iostream>
« Reply #3 on: January 05, 2009, 03:37:40 pm »
Programming involves solving problems intelligently.

How many people sign up to TKC each week asking the same questions- only to be referred to the search feature.

If you can't think for yourself C++ is not for you!

[TKC]Symantic

  • The Indifferent Character
  • The Central Committee
  • Heckler
  • *
  • Posts: 1647
  • I can has personal text?
    • View Profile
Re: {C++} Basic tutorial (part 2) <iostream>
« Reply #4 on: January 05, 2009, 03:41:48 pm »
What are you thoughts on the language by the way?
my thoughts are its more efficient than vb6, and that its cross-compatable language between most all major platforms.

i believe that most of the members on-line are people who are self-taught, there is not really a class you can take specifically for game hacking (especially for the younger ones) and that some of the people who wish to learn a language may need other types of instruction other than a tutorial which is a one way information stream, some of the (or any) of the people may not understand something this way.

think about this, let me think of something specific, if i was to try to teach relay logic in a tutorial it wouldn't really work unless you knew really what a relay was. there are many types of relays, spst,dpst,spdt and dpdt are a few used in electrical systems. now if i said connect the N/O side of the dpdt relay(t) to the load of the circuit and place a spst switch to the coil of relay(t) you could look at a diagram and know where to put the wires, but what is the point behind it? you don't know what your doing but the circuit works. if it was to not work then what do you do?

i think that's what the main problem is, people don't learn the basics of something maybe because they don't know how to go about it or they honestly are just lazy bums

-Symantic
Enjoy your creative game-play, whatever that may include.

Subsky

  • Insane Joker
  • ****
  • Posts: 504
  • Subskii
    • View Profile
Re: {C++} Basic tutorial (part 2) <iostream>
« Reply #5 on: January 05, 2009, 06:45:10 pm »
I am certainly no electrical engineer, but I'm highly motivated and determined to learn.  I don't understand what you were saying about relay circuits- but with a few books, pen, pencil, paper and the internet I'm sure I could work it out.  Not in a day, of course- and not to your level or confidence or expertise but to a satisifactory level.

The problem is: most kinder hackers want to become elite overnight and they give up when they realise it isn't going to happen.

[TKC]Lasher

  • Heckler Apprentice
  • ****
  • Posts: 1394
  • IWHBYD
    • View Profile
    • http://www.tkc-community.net
Re: {C++} Basic tutorial (part 2) <iostream>
« Reply #6 on: January 09, 2009, 08:56:24 am »
Replied?
Whenever work feels overwhelming, just remember that you are going to die.

MrMedic

  • MasstKer
  • ********
  • Posts: 8900
  • programmer/dev/software engineer
    • View Profile
Re: {C++} Basic tutorial (part 2) <iostream>
« Reply #7 on: January 09, 2009, 09:07:18 pm »
good tutorial symantic  , im glad to see you are venturing into c , good work man, well done :)
EnCoded Message: i3iy9yl8kr2xf3g2Txs3pr6ye3ya7jg5ty2z

https://www.youtube.com/watch?v=62_7-AYfdkQ
you need a paypal account for the private versions.

Website:
http://bit.ly/medic101

Teamspeak 3: 85.236.101.5:10157

ZOldDude

  • The Unknown Rank!
  • Administrator
  • MasstKer
  • *
  • Posts: 20874
  • Old School TKC
    • View Profile
    • Admin
Re: {C++} Basic tutorial (part 2) <iostream>
« Reply #8 on: January 10, 2009, 02:03:40 pm »
I understand electrical/electronics and can read schematics.
Worked most my life as a general contractor and did electronics "on the side" for over 25 years before I got into computer building and tweeking systems.

*While we crash and burn, small, low tech, agrarian societies such as the Hmong in the mountains of Laos will continue on without so much as blinking an eye.*

[myg0t]wav

  • Cheater Apprentice
  • *
  • Posts: 11
    • View Profile
Re: {C++} Basic tutorial (part 2) <iostream>
« Reply #9 on: February 12, 2009, 12:27:04 pm »
system("pause"); is bad practice instead consider using getch()
« Last Edit: February 15, 2009, 12:24:12 pm by [myg0t]wav »

hardvirus

  • Intentional Cheater
  • **
  • Posts: 25
    • View Profile
Re: {C++} Basic tutorial (part 2) <iostream>
« Reply #10 on: October 31, 2009, 11:32:33 pm »
i know c++(learned at school,got to the national olimpics,i got 12 from 97 people),but how do you use c++ to make a trainer?
Could somone post a tutorial?

[TKC]Symantic

  • The Indifferent Character
  • The Central Committee
  • Heckler
  • *
  • Posts: 1647
  • I can has personal text?
    • View Profile
Re: {C++} Basic tutorial (part 2) <iostream>
« Reply #11 on: November 01, 2009, 03:06:38 am »
i know c++(learned at school,got to the national olimpics,i got 12 from 97 people),but how do you use c++ to make a trainer?
Could somone post a tutorial?
national Olympics of c++?

umm, the best thing i could tell you other than pickup a book and learn how everything works would be to type in something like "c++ trainer source code" in google.

i just did and a few sources come up, for different games of course but it should be hard to figure out how to change it to make it work for your own good. from there you could take parts out or include some of your own and eventually write your own complete source code.

if you have the background of C++ then you should be more than fine.

-Sym

Enjoy your creative game-play, whatever that may include.

hardvirus

  • Intentional Cheater
  • **
  • Posts: 25
    • View Profile
Re: {C++} Basic tutorial (part 2) <iostream>
« Reply #12 on: November 01, 2009, 06:42:32 pm »
National Olimpycs=A national official contest (there's one for every school subject) in witch only the best participate(it's done once every year),in this contest you've got to be the first or the seccond in your state to participate
Do i need to know any othe languadges as assembly or hexidecimal?(i'm only 16 so i have a lot of time to learn)
Thanks in advance!

MrMedic

  • MasstKer
  • ********
  • Posts: 8900
  • programmer/dev/software engineer
    • View Profile
Re: {C++} Basic tutorial (part 2) <iostream>
« Reply #13 on: November 01, 2009, 07:07:24 pm »
there is no language called hexidecimal , hexidecimal is a numeric form m8 (0123456789ABCDEF 0-15), as for other languages though it would be a benefit if you learn asm as well as c , but for what you need you should try visual basic or python to start off with to give you a 'basic' idea of structuring your code but if like you say you know the c language and are proficient in it then thats all well and good.
EnCoded Message: i3iy9yl8kr2xf3g2Txs3pr6ye3ya7jg5ty2z

https://www.youtube.com/watch?v=62_7-AYfdkQ
you need a paypal account for the private versions.

Website:
http://bit.ly/medic101

Teamspeak 3: 85.236.101.5:10157

Subsky

  • Insane Joker
  • ****
  • Posts: 504
  • Subskii
    • View Profile
Re: {C++} Basic tutorial (part 2) <iostream>
« Reply #14 on: November 02, 2009, 01:32:11 am »
I took part in something similiar when I was younger.

You shouldn't be focusing on asm or c for this competition, although I do think you should know binary/hex/octal conversions.

My guess is that you need to be able to write code to solve problems they give you, and your biggest concern will be time.  You just can't even write throw away programs very quickly in lower level languages.  

As much as I think VB is a toy, VB.NET does have access to the BCL.  Get to know your way around there.

SUbsky