首页 > 代码库 > Namespace, string, vector and array

Namespace, string, vector and array

1. Headers should not include using declaration

Code inside headers ordinarily should not include using declarations. The reason is that the contents of a header are copied into the including program‘s text. If a header has a using declaration, then every program that includes that header gets the same using declaration. As a result, a program that does not intend to use the specified library name might encounter unexpected name conflicts.

2. Deal with characters in string( with functions in <cctype> header)

  isalnum(c): true if c is a letter or digit

  isalpha(c): true if c is a letter

  isdigit(c): true if c is a digit

  islower(c): true if c is a lowercase letter

  isspace(c): true if c is a whitesapce

  isupper(c): true if c is an uppercase letter

  tolower(c): return lowercase letter

  toupper(c): return uppercase letter

3. Different between pointer and iterator

Pointer is a built-in type whereas iterator is a class. Pointer is avaiable for all type of objects whereas iterator is only available for containers.

4. Vector and array

Similarity: they all store a collection of variables of a single type and we can access their element by position. 

Difference: elements in array is stored in continuous space whereas elements in vector can be stored in non-continuous space. Array is fixed size and we can‘t add or remove element from a array. On the contrary, the size of a vector can be changed by adding or removing elements from it.

4. There is no arrays of references

 

Namespace, string, vector and array