Thursday, January 12, 2012

C++ For Beginners (Terminal/Console Application)

So I got bored and decided to start learning C++ and of course I will be starting with terminal applications. I don't think I am going to do this as a regular tutorial but more as a tutorial application. It will help me learn it as well, so here we go my learn as i go program ( I will update it as i do more and more etc... then it will be posted to the usual sources notifying as such. I hope someone gets something out of this, other then myself of course.)



#include <iostream> // think of it as input output stream (makes it so  so can accept and post information)...

int main(int argc, char **argv) {
  std::cout << "This is my little demo of basic input and output in C++" << std::endl;
  std::cout << "The code to put this text into the terminal is std::cout" << std::endl;
  std::cout << "std is a namespace in the file iostream which is a library" << std::endl;
  std::cout << "of input and output codes. The cout is the function from that" << std::endl;
  std::cout << "namespace that we want to use. cout basically just means print" << std::endl;
  std::cout << "to screen, and endl is end line." << std::endl << std::endl;
  sleep(5);
  std::cout << "Calling a namespace over and over just to print lines of code can" << std::endl;
  std::cout << "be a pain in the @zz and they knew it so there is a cool little" << std::endl;
  std::cout << "ability set your namespace and that makes it so you can skip the" << std::endl;
  std::cout << "std:: in front and just use cout, cin, endl which will save alot" << std::endl;
  std::cout << "time and frustration." << std::endl << std::endl;
  sleep(5);
  using namespace std;
  cout << "and apparently you can set the namespace at most points in the program" << endl;
  cout << "as I just used the code \" using namespace std; \" prior to the last" << endl;
  cout << "line of code and no longer have to use std:: in front of every command" << endl;
  cout << "thank god for that lol.";
  cout << endl << endl << endl;
  sleep(5);
  cout << endl << "Now lets try a little bit of input, first off you would have to define" << endl;
  cout << "your input properly, lets say the input variable is \"a\" the ways to" <<endl;
  cout << "define this are as follows;" << endl << endl;
  cout << "char a (Defines a as a character)" << endl;
  cout << "short int a (Defines a as a short integer)" << endl;
  cout << "int a (Defines a as an integer)" << endl;
  cout << "long int a (Defines a as a long integer)" << endl;
  cout << "bool a (Defines a as a boolean value)" << endl;
  cout << "float a (Defines a as a floating point number)" << endl;
  cout << "double a (Defines a double precision floating point number)" << endl;
  cout << "long double a (Defines a as a long double precision floating point number)" << endl;
  cout << "wchar_t a (defines a as a wide character)" << endl;
  cout << "string a (defines a as a string)" <<endl;
  sleep(5);
  cout << "Now to give each of them a shot and see what is returned"<< endl;
  char a;
  cout << "Your char input? "; cin >> a;
  cout << endl << "Your input into a is \"" << a << "\" is it what you input" << endl;
  cout << "As you may notice char seems to only take the first character of the input" << endl;
  sleep(3);
  short int b;
  cout << "Your short int input? "; cin >> b;
  cout << endl << "Your input seen by short int was \"" << b << "\"";
  cout << endl << "The maximum integer that short will hold is 32767 and the minimum of -32768" << endl;
  sleep(3);
  int c;
  cout << "Your int input? "; cin >> c;
  cout << endl << "Your input seen by int was \"" << c << "\"";
  cout << endl << "The maximum integer that short will hold is 2147483647 and the minimum of -2147483648" << endl;
  return 0;
}