|
#include
|
<headerfile>
|
|
Common Headers / Libraries
|
|
|
#include <stdio.h>
|
I / O functions
|
|
#include <string.h>
|
string functions
|
|
#include <time.h>
|
time functions
|
|
#include <stdlib.h>
|
memory, rand, ...
|
|
#include <math.h>
|
math functions
|
|
#include <iostream.h>
|
|
|
#include <fstream.h>
|
I / O file functions
|
|
#include "myfile.h"
|
Insert file in current directory
|
|
using namespace std;
|
|
// One line comment text
|
|
/* multiple line block comment text */
|
|
NUMBER
int a; float a;
|
|
CHARACTER
char car; string s;
char car = ‘c’; string s = “hola mon”; |
|
BOOL
bool b = false/true;
|
|
cin
|
cin >> var
|
|
cout
|
cout<<"The variable has"<<var
|
|
+ Add
|
- Less
|
|
* Mult
|
/ Div
|
|
% Mod
|
|
|
++var / --var
|
var++ / var--
|
|
A == B
|
if A is equal to B, this is true; otherwise, it’s false
|
|
A != B
|
if A is NOT equal to B, this is true; otherwise, it’s false
|
|
A < B
|
if A is less than B, this is true; otherwise, it’s false
|
|
A > B
|
if A is greater B, this is true; otherwise, it’s false
|
|
A <= B
|
if A is less than or equal to B, this is true; otherwise, it’s false
|
|
A >= B
|
if A is greater or equal to B, this is true; otherwise, it’s false
|
|
A ! B
|
if A
|
|
A && B
|
if condition A and condition B are true, this is true; otherwise, it's false.
|
|
A || B
|
if condition A or condition B is true, this is true; otherwise, it's false.
|
|
type array_name [ # of elements ];
int price [10];
|
|
type array_name [# elements] [# elements];
int price [5] [10];
|
|
if sentence
|
|
|
|
if ( conditional ) {
// do something } else if ( another_conditional ) { // do something else } else { // do something as default } |
|
while sentence
|
|
|
|
while ( conditional ) {
// do something } placing “break;” breaks out of the loop. placing “continue;” jumps to next loop. |
|
for sentence
|
|
|
|
for ( init; test; command ) {
// do something } "break;" and "continue;" identical effects. |
|
do while sentence
|
|
|
|
do {
//do something } while (bool expression); |
|
switch case sentence
|
|
|
|
switch ( variable )
{ case value1: // do something; break; case value2: // do something else; break; [default: // do something by default: break; ] } |
#include <fstream.h>
ifstream file; //read buffer
ofstream file; //write buffer
file.open ("filename", [file mode constant]);
* //Test if the file was created *
if(fs.is_open()) if(fs)
*//Reads/Writes like cin and cout*
file >> var; //Read
file << ''Text: "<< var << endl; //Write
*//Read Entire line*
getline (file,String);
*//Read until it arrives at the end of file*
while(file.eof())
*//Detect if the read/write fail*
if(file.fail())
*//Close File*
file.close();
* //Declaration*
** *void* ProcedureName()**
{
// do something
}
*//Call to procedure*
**ProcedureName();**
*//Declaration*
** [*returnType*] functionName ( [*input1Type* input1Name, *input2Type* input2Name, ....] ) **
{
// do something
return value; // value must be of type returnType
}
*//Call to function*
**[returntype var =] functionName ([*input1Type* input1Name, *input2Type* input2Name, ....])**
|
Structure declaration :
|
|
|
struct <structure_name>
{ <type> <name>, <name>, ... ; <type> <name>, <name>, ... ; } |
|
|
Var declaration with structure type :
|
|
|
<structure_name> var_name;
|
|
|
Acces to structure :
|
|
|
var_name.name;
|
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.