Notas
Basics of C++
Conteúdo das notas (2)
Página 1
Control IO
~ Page Overview ~
The Standard Library & Namespace
iostream
Outputting Data
Receiving Data
sstream
stringstream
~ Page Notes ~
~ The Standard Library & Namespaces ~
In Order to use any function/class from the Standard Library you must use it's namespace "std", followed by 2 semicolons and the function/class you wish to access.
~ #include ~
std::cout << var << " This is a chained output. \n";
Makes use of the insertion operator (<<). This inserts the following data to the stream that precedes it.
Line Breaks may be done either using "\n" or inserting the "endl" manipulator.
cout << "line.\n";
cout << "line." << std::endl;
std::cin >> int a >> double b;
Makes use of the extraction operator (>>), which is followed by the variable that will hold the extracted data.
The data is extracted as whatever type follows the extraction operator.
Only very simple programs should utilize "cin" for data extraction, since there is the possibility of no data being extracted and a variable left undefined, creating errors during said variables implementation. Instead use:
std::getline( cin, var ) ;
Note that data is extracted as a string.
When working with strings, cin recognizes white spaces, tabs, newlines etc. as the termination of value extraction.
~ #include ~
defines a type called stringstream
Can be used to turn strings into numerical values.
std::string mystr ("1204");
int myint;
std::stringstream(mystr) >> myint;
std::cout << myint+6;
1210
Página 2
FUNDAMENTAL TYPES
~ Page Overview ~
Type void
Integral's
Type char
Type int
Floating Point Numbers
Type float
Type double
Type long double
Boolean
Data Models
How 32 bit systems store variables
How 64 bit systems store variables
~ Page Notes ~
To determine the size of a type in bytes (8 bits) use "sizeof(var);"
~ Void ~
An empty set of values
An incomplete type
objects, arrays, & references are disallowed.
~ Integral's ~
Ranges based on Microsoft's default C++
You can double the size of any integral by preceding the type with the "unsigned" keyword, but in doing so the sign is always ignored.
( e.g. The range of a 16 bit, unsigned int is [0, +65,536] )
char
contains members of the basic execution character set. ( Microsoft C++ has a default of ASCII )
int
To size an integer precede w/ "__intb' where b = the bit size.
__int8
Range [-128 , + 127
__int16
Range [-32,768 , +32768]
Aka short, short int, signed short int
__int32
Range [-2,147,483,648 , +2,147,483,648]
Aka int, signed int
__int64
Range [-9,223,372,036,854,775,808 , +9,223,372,036,854,775,808]
Aka long, long int, signed long int
~ Floating Point ~
float
Range [3.4e +/-38] (for both +/-)
Smallest floating point #
4 bytes
double
Range [1.7e +/- 308] (for both +/-)
>= float
8 bytes
long double
>= double
In Microsoft's C++ double & long double have identical representation.
Considered a separate type from double.
~ Boolean ~
Holds either a true or false value
~ Data Models ~
32 bit systems
LP32 or 2/4/4 (int is 16-bit, long & pointers are 32 bits)
Win16 API
ILP32 or 4/4/4 (int, long & pointer are 32 bits)
Win32 API
Unix & Unix-like systems (Linux, Mac OS X)
64 bit systems
LLP64 or 4/4/8 (int & long are 32 bits, pointer is 64 bits)
Win64 API
LP64 or 4/8/8 (int is 32 bits, long & pointer are 64 bits)
Unix & Unix-like systems (Linux, Mac OS X)
Informações
- Descrição
- Foundational information for the use of the C++ programming language. Notes taken from: Caleb Curry - Youtube Cyrill Stachniss - Youtube (Recorded lectures @ Universitat Bonn)
- Criado por
- Oscar Rojas · abr 2020
- Atualizado
- 2 abr 2020
- Visualizações
- 26
- Tags
- Avaliação