Beruflich Dokumente
Kultur Dokumente
1. signature of main()
- in C, NULL is 0 or ((void*)0)
- in C++, NULL is (int)0
- use 0 or nullptr, do not use NULL
- standard: you can always delete a NULL pointer
- always use
#include <cmath>
- not "math.h" or <math.h>
- system header files
#include <iostream> // C++ standard library headers
#include <cstdlib> // C standard library headers
- all names in the std namespace
- No.
- Principle: mimimize variable scope, tighten scope as much as possible
double num;
string teststr("14.2");
stringstream converter;
converter << teststr;
converter >> num
-or-
double num = boost::lexical_cast<double>(teststr);
double num(14.2);
string teststr;
strinstream converter;
converter << num;
converter >> teststr;
-or-
string str = boost::lexical_cast<string>(num);
#ifndef MYHEADER_H
#define MYHEADER_H
...
#endif
ESOTERICs:
---------- ---------- ---------- ---------- ---------- ----------
C++ does not allow modification of temporaries of built-in type
vector<T> myvector;
myvector.end()
need not return an object of type T,
instead it may return a temporary of built-in type
so, you cannot use --myvector.end()
instead use
myvector.end()-1
to access the last element of the vector