set

他们俩都往 set 里增加一个元素,区别在于新元素的构造上。emplace 使用直接构造,insert 使用复制构造

C++默认参数

函数的默认参数值,即在定义参数的时候同时给它一个初始值。在调用函数的时候,我们可以省略含有默认值的参数。也就是说,如果用户指定了参数值,则使用用户指定的值,否则使用默认参数的值。

map.count()

count()是返回key出现的次数,在map里,key只能是0和1
例如 我们判断一个key是否存在,如果存在就输出,不存在就不输出
map<string, int> a;
cout<<a["abc"]<<endl; //这个肯定是错的

if(a.count("China"))        //对了
    cout<<a["China"]<<endl;

// string::size
#include <iostream>
#include <string>

int main ()
{
  std::string str ("Test string");
  std::cout << "The size of str is " << str.size() << " bytes.
";
  return 0;
}




C++中substr函数的用法

#include<string>
#include<iostream>
using namespace std;

main()
{
string s("12345asdf");
string a=s.substr(0,5);       //获得字符串s中 从第0位开始的长度为5的字符串//默认时的长度为从开始位置到尾
cout<<a<<endl;
}

输出结果为:

12345

 http://blog.sina.com.cn/s/blog_9d85c1900102v1rm.html

返回一个从指定位置开始的指定长度的子字符串。

stringvar.substr(start [, length ])

 
gitline()函数详解
http://blog.sina.com.cn/s/blog_60263c1c0101ck25.html
原文地址:https://www.cnblogs.com/kilen/p/6554018.html