C++

From Botdom Wiki
Jump to: navigation, search
C++ (C Plus Plus)
Paradigm Multi-paradigm
Appeared in 1983
Designed by Bjarne Stroustrup
Influenced by C, Simula, Ada 83, ALGOL 68, CLU, ML
Influenced Ada 95, C#, Java, PHP, Perl, D, Aikido, Dao

C++ (C Plus Plus, CPP, or "C with Classes") is a general purpose programming language. It's considered a Mid-Level language as it comprises a combination of both high-level and low-level language features.


Examples

Simple "Hello, World!" program.;

<cpp>#include <iostream> // So we can use std::cout, etc.

int main() {

  std::cout << "Hello, world!\n"; // Output: Hello, World!
  return 0;

}</cpp>

Getting user input;

<cpp>#include <iostream> // So we can use std::cout, etc.

int main() {

  char buffer[256]; // We will store the input here
  std::cout << "Enter your name: "; // Ask the user to enter their name
  std::cin >> buffer; // After they hit the [Enter] key, we store it
  std::cout << "Hello, " << buffer << "!\n"; // Say Hello to the user!
  return 0;

}</cpp>

shortcuts;

<cpp>#include <iostream> // So we can use std::cout, etc. using namespace std; // Now we can just type cout, cin, etc

int main() {

  char buffer[256]; // We will store the input here
  cout << "Enter your name: "; // Ask the user to enter their name
  cin >> buffer; // After they hit the [Enter] key, we store it
  cout << "Hello, " << buffer << "!\n"; // Say Hello to the user!
  return 0;

}</cpp>

Classes;

<cpp>#include <iostream>

class TestClass { public:

  virtual void SayHello() {std::cout << "Hello, World!";}

};

int main() {

  TestClass myClass;
  myClass.SayHello();
  return 0;

}</cpp>