string s(cp); | initialize a string from the null-terminated C-style string pointed to by cp |
getline(is, s); | Reads characters up to the first newline from input stream is into s |
defines a new interface on top of an underlying;takes a container and makes it into a stack | explain an ADAPTOR |
queue, priority_queue (#include <queue> for both), and stack | three sequential container adaptors |
a vector, list, or deque | what are the sequential containers |
stack (vector,list,Ddeque), queue (push_front- list,Ddeque) pio_que(random access Dvector or deque) | what can you build a stack, a queue and a priority_queue on? |
pair<string, string> anon; pair<string, string> author("James", "Joyce") | construct a pair that holds two strings Joyce and John |
make_pair(first,last); | equivalent to pair<string, string>(first, last); // but types are inferred |
elements are stored and retrieved by a key;may contain only a single el with given key | describe ASSOCIATIVE CONTAINERS |
map, and set | 2 primary associative containers |
cannot be defined from a size no way to know what values to give the keys | can we define ass containers using size? |
map<string, int> word_count; | // empty map from string to int , indexed by string |
the key type must define the < operator (comparison function) | what is the requirement on the key type? |
map<K, V>::value_type = e.g. pair<const string, int> | how to retrieve a pair that holds the key and value of a given element |
a pointer to an element | iterator is simply.. |
map<string, int>::iterator map_it = word_count.begin(); | *map_it is a reference to a pair<const string, int> object[map_it->first; // the key for this elemen |
word_count.insert(map<string, int>::value_type("Anna", 1)); or use make_pair | insert an element to a map |
word_count["Anna"] = 1; // value is iniitialize to 0, pair inserted;then fetched and given 1 | // insert default initialzed element with key Anna; then assign 1 to its value |
int occurs = word_count["foobar"]; | retrieve a value from map word_count with key "foobar" |
m.count(k) (useful for multimaps); m.find(k); (returns an iterator; end iterator if not present) | how to check if the key is present (and how to check if it exists and then maybe use it?) |
erase on seq containers return an iterator to the next element; erase on map return void | what's the difference in behaviour of erase operations on map and on seq containers |
m.erase(k); returns a size_type count of how many elements were removed! can be used in if(...) | how to delete a single element on map and whats the return type |
..::const_iterator map_it=w.begin() while (map_it != word_count.end()) {map_it->first ++map_it;} | how to traverse a map;Like any other container map has begin and end op tht yield iterators; |