#include <headerfile> A == B if A is equal to B, this is true; if sentence
Common Headers / Libraries otherwise, it’s false
if ( conditional ) { A != B if A is NOT equal to B, this is true; // do something #include <stdio.h> I / O functions otherwise, it’s false } #include <string.h> string functions A<B if A is less than B, this is true; else if ( another_conditional ) { #include <time.h> time functions // do something else otherwise, it’s false #include <stdlib.h> memory, rand, ... } A>B if A is greater B, this is true; else { #include <math.h> math functions otherwise, it’s false // do something as default #include <iostream.h> A <= B if A is less than or equal to B, this is } true; otherwise, it’s false #include <fstream.h> I / O file functions while sentence A >= B if A is greater or equal to B, this is #include "myfile.h" Insert file in current true; otherwise, it’s false while ( conditional ) { directory // do something A!B if A } Namespaces A && B if condition A and condition B are placing “break;” breaks out of the loop. true, this is true; otherwise, it's false. using namespace std; placing “continue;” jumps to next loop. A || B if condition A or condition B is true, for sentence Comments this is true; otherwise, it's false. for ( init; test; command ) { Boolean expressions in C++ are evaluated left t // One line comment text // do something o right! /* multiple line block comment text */ } "break;" and "continue;" identical Arrays Basic Variable Types effects. type array_name [ # of elements ]; do while sentence NUMBER int price [10]; do { int a; float a; type array_name [# elements] [# elements]; //do something CHARACTER } while (bool expression); int price [5] [10]; char car; string s; switch case sentence char car = ‘c’; string s = “hola mon”; · Array index starts at 0. switch ( variable ) · Ex: Access 3rd element : cout<<price [2]; BOOL { bool b = false/true; case value1: // do something; break; Basic input / Output Operators case value2: cin cin >> var // do something else; cout cout<<"The variable has"<<var break; [default:
Basic Operators / Math Operators // do something by default:
break; ] + Add - Less } * Mult / Div
% Mod
++var / --var var++ / var--
By jofre pla Published 4th April, 2016. Sponsored by ApolloPad.com
cheatography.com/jofre-pla/ Last updated 19th May, 2016. Everyone has a novel in them. Finish Yours! Page 1 of 2. https://apollopad.com C++ for beginners Cheat Sheet by jofre pla via cheatography.com/26595/cs/7478/
} //Test if the file was created //Call to procedure if(fs.is_open()) if(fs) ProcedureName(); Var declaration with structure type :
//Reads/Writes like cin and cout <structure_name> var_name;
In the procedures we don't receive variables file >> var; //Read and don't return other variable. Acces to structure : file << ''Text: "<< var << endl; var_name.name; //Write Functions //Read Entire line //Declaration getline (file,String); [returnType] functionName ( //Read until it arrives at the end [input1Type input1Name, of file input2Type input2Name, ....] ) while(file.eof()) { //Detect if the read/write fail // do something if(file.fail()) return value; // value must be //Close File of type returnType file.close(); } File Mode Constants //Call to function ios::in //Opens file for reading [returntype var =] functionName ios::out //Opens file for writing ([input1Type input1Name, ios::app //Causes output to be appended at input2Type input2Name, ....]) EOF ios::trunc //Destroys the previous contents We have two methods to create and call ios::nocreate //Causes open() to fail if file functions: doesn't already exist passed with values and passed for reference. ios::noreplace //Causes open() to fail if file Pass by reference : we put & before variable already exists in the declaration.
By jofre pla Published 4th April, 2016. Sponsored by ApolloPad.com
cheatography.com/jofre-pla/ Last updated 19th May, 2016. Everyone has a novel in them. Finish Yours! Page 2 of 2. https://apollopad.com