/ Output Tutorial
Writen by fatal
tuturial is writen for beginer to the c++ language, first off to the beginer
of c++. The most common error is forgeting the semi-colin at the end of each
line. But theirs an exception to this, when using loops( ie: for loop, do/while
loop, & while loop) you dont put a semi-colin at the end
for( x=1; x<8; x++);
cout<< x << endl;
you add the semi-colin it will ignore the cout command and continue with the
program. That the only time where you dont put the semi-colin.
you input an integer, char, or arrays. You will be using the cin command.
will take the inputed data and store it to the varible. Arrays are different
story tho, to make an input to a char array, you have to use cin.get and cin.ignore.
char array; // Declare a char array
21); // we do this instead of cin because it can store everything ex: fatal
'\n'); // This is to clear the stream
better to use cin.get than cin, because cin will store everything up to a space,
but cin.get will store everything you input like Jane Doe. cin would just sote
Jane if you inputed Jane Doe.
than storing to arrays, just using cin for numbers and charactors will be fine.
output all it is, is using cout.
you want to output an interger:
int x = 8;
x << endl;
Integer: " << x << endl;
outputing is very simple, thats all i will explain.
it all together...
a simple program using everything that I explained in this tutorial:
// Needed for the cin, cout, cin.get, and cin.ignore
main() // Start of main function
in a Integer: "; // Using cout to give user instructions
cin>> x; // Storing the inputed number to x
Integer Inputed is: " << x << endl; // Outputing what the user
a single charactor: "; // Asking user to input a charactor
cin>> i; // Storeing the charactor to i
Charactor Inputed is: " << i << end;// Outputing what was inputed
in your full name: ": // Asking user for their full name
cin>> arrray;// Storing full name to array
Full Name is: " << array << endl;
// As you will notice it will only output everything up to the space
in your full name again: ";
cin.get( array2, 21); // Gets everythin that was inputed
cin.ignore(80, '\n'); // Clears stream
full name is: " << array2 << endl;
// Notice how you full name is outputed this time
0; // Tells the complier that you program is done
I hope that cleared up your confusion on input/output. In my opinion this is
a great tutorial on input/output, and i hope it was good enough to help you.