1. Header files
#include <vector>//vector containers
#include <map>//map containers
#include <algorithm>//sort () functions need to be added
2. Macro definition
#define OK 0
#defien ERR 1
or defined as other.
3. String problems
Enter the parameter with a character pointer, be sure to check if it is null
The incoming output pointer, if not specifically stated to allocate space for itself, also check whether NULL
Do not change the incoming string, you need to change the words, you can define a new one, and then memcpy come over to deal with
For example:
char* newstr = (char*) malloc ((strlen (PINPUTSTR) +1) * sizeof (char)); Note +1
memset (newstr, 0, (strlen (PINPUTSTR) +1) * sizeof (char)); Be sure to memset after malloc//The last parameter can be copied from the above sentence.
memcpy (Newstr, Pinputstr, strlen (PINPUTSTR));
The pass-through is char*, or it can be processed by string:
String Str_c, Str_e;
Str_c = Pstrchinese; You can assign this value
Str_e = Pstrenglish;
Insert: String has a method, C_str (), which converts the string type to a literal in the C language.
To assign a value of type string to char* (allocated space), memecpy:
memcpy (Poutputstr, Str_e.c_str (), str_e.length);
4.map
The map container is like a hash table, like a dictionary in Python, like an object in JavaScript, is a key-value pair.
Created: Map<int, int> Transmap; Defines a variable transmap, which is a map container and the key values are of type int
Create iterators: Map<int, int>::iterator it; It's an iterator.
Add: The simplest way is transmap[key] = value;
Find: Transmap.find (value); The Find function returns the index value, which, if not found, returns the last index value, which is the value of Transmap.end ().
Traversal: The iterator can be used:
for (it = Transmap.begin (); It! = Tansmap.end (); it++) {
cout<<it->second<< ""; The first value of the iterator is the key, the second is the value, so It->second is the value found, or (*it). Second
}
Delete key-value pairs:. Erase (index value)
it = Transmap.find (value);
Transmap.erase (IT);
Note When traversing delete, the index value +1 is to be removed before deletion, such as:
for (it = Transmap.begin (); It! = Transmap.end ();) {
cout<<it->fitst<< ":" <<it->second<<endl;
Transmap.erase (it++);
}
Clear Map Container: Map.clear ();
Sort: The key-value pairs in map are from small to large rows, and map does not support the sort function;
OJ points of attention and summary of knowledge points