C++语法查漏补缺
越来越发现自己编程和数学基础薄弱了,羞愧死!!!!!!!!!!!!!!!!!!
public member function <string>
std::string::substr
string substr (size_t pos = 0, size_t len = npos) const;
Generate substring
Returns a newly constructed string object with its value initialized to a copy of a substring of this object.
The substring is the portion of the object that starts at character position pos and spans len characters (or until the end of the string, whichever comes first).
子字符串substring是从字符串开始位置pos并跨越长度为len的字符(或直到字符串结尾,以先到者为准)的对象的局部。
std::getline (string) C++11
(1)
istream& getline (istream& is, string& str, char delim);
istream& getline (istream&& is, string& str, char delim);
(2)
istream& getline (istream& is, string& str);
istream& getline (istream&& is, string& str);
Get line from stream into string 从文件流中获取行到字符串
Extracts characters from is and stores them into str until the delimitation character delim is found (or the newline character, ‘\n’, for (2)).
The extraction also stops if the end of file is reached in is or if some other error occurs during the input operation.
If the delimiter is found, it is extracted and discarded (i.e. it is not stored and the next input operation will begin after it).
Note that any content in str before the call is replaced by the newly extracted sequence.
Each extracted character is appended to the string as if its member push_back was called.
从is
中提取字符并将它们存储到str
中,直到找到定界字符定界符(或(2)的换行符'\n'
)。
如果到达文件末尾或者在输入操作过程中发生其他错误,则提取也会停止。
如果找到分隔符,它将被提取并丢弃(即它不被存储并且下一个输入操作将在它之后开始)。
请注意,在调用之前str
中的任何内容都被新提取的序列替换。
每个提取的字符都会附加到该字符串,就像调用其成员push_back
一样。
3.map
std::map
template < class Key, // map::key_type
class T, // map::mapped_type
class Compare = less<Key>, // map::key_compare
class Alloc = allocator<pair<const Key,T> > // map::allocator_type
> class map;
Maps are associative containers that store elements formed by a combination of a key value
and a mapped value, following a specific order.
In a map, the key values are generally used to sort and uniquely identify the elements,
while the mapped values store the content associated to this key. The types of key and
mapped value may differ, and are grouped together in member type value_type, which is a pair
type combining both:
typedef pair<const Key, T> value_type;
map是一种关联容器,按照特定顺序存储由key值和value值组合形成的元素。
在map中,key通常用于对元素进行排序和唯一标识,而value存储与此key关联的内容。key和value的类型可能不同,并且在成员类型value_type中组合在一起,这是一种结合了以下两者的成对的类型。
public:
map<string,string>data;
string key = str.substr( 0, pos );
string value = str.substr( pos+1, str.length() );
data[key] = value;