c++ string的substr函数有两个参数
substr(posi,length):从posi开始选取length个字符
string s1="123456qwe";
cout<<s1.substr(0,6)<<endl; //输出:123456
其中posi是必填参数,当posi超出字符串长度时报错
length是选填参数,
当posi+length>=字符串长度时,默认从posi取到字符串尾端;
当不填length时,也默认从posi取到字符串尾端;
string s2="0123456";
cout<<s2.substr(2,7)<<endl; //输出23456
cout<<s2.substr(2)<<endl; //输出23456
cout<<s2.substr(10)<<endl; //提示错误