1 2 3 4 5 6 7 8 9 | #include<string> #include<iostream> using namespace std; int main() { string s( "12345asdf" ); string a = s.substr(0,5); //获得字符串s中从第0位开始的长度为5的字符串 cout << a << endl; } |
输出结果为:12345
【更多】
0. 用途:一种构造string的方法
1. 形式:s.substr(pos, n)
2. 解释:返回一个string,包含s中从pos开始的n个字符的拷贝(pos的默认值是0,n的默认值是s.size() - pos,即不加参数会默认拷贝整个s)
3. 补充:若pos的值超过了string的大小,则substr函数会抛出一个out_of_range异常;若pos+n的值超过了string的大小,则substr会调整n的值,只拷贝到string的末尾
共线性图 | Alluvial Diagrams | Parallel plot | Parallel Coordinates Plot
绿色地狱
deepnude | 福利
文献阅读 | A single-cell molecular map of mouse gastrulation and early organogenesis
Seurat V3.0
文献阅读 | Molecular Architecture of the Mouse Nervous System
《我的团长我的团》
RNA剪接体 Spliceosome | 冷冻电镜 | 结构生物学
文献阅读 | Resetting histone modifications during human parental-to-zygotic transition