C++ string类insert用法总结
body, table{font-family: 微软雅黑; font-size: 13.5pt}
table{border-collapse: collapse; border: solid gray; border-width: 2px 0 2px 0;}
th{border: 1px solid gray; padding: 4px; background-color: #DDD;}
td{border: 1px solid gray; padding: 4px;}
tr:nth-child(2n){background-color: #f8f8f8;}
basic_string& insert( size_type index, size_type count, CharT ch ); 在index位置插入count个字符ch |
string str = "meihao";
string sstr = str.insert(0,2,'a');
cout<<sstr<<endl; //aameihao
|
basic_string& insert( size_type index, const CharT* s ); index位置插入一个常量字符串 |
string str = "meihao";
string sstr = str.insert(1,"hello~");
cout<<sstr<<endl; //mhello~eihao
|
basic_string& insert( size_type index, const CharT* s, size_type count ); index位置插入常量字符串中的count个字符 |
string str = "meihao";
string sstr = str.insert(1,"hello~",3);
cout<<sstr<<endl; //mheleihao
|
basic_string& insert( size_type index, const basic_string& str ); index位置插入常量string |
string str = "meihao";
string sstr = str.insert(1,str);
cout<<sstr<<endl; //mmeihaoeihao
|
basic_string& insert( size_type index, const basic_string& str,
size_type index_str, size_type count );
index位置插入常量str的从index_str开始的count个字符
|
string str1 = "meihao";
string str2 = "hello~";
string sstr = str2.insert(6,str1,3,3);
cout<<sstr<<endl; //hello~hao
|
basic_string& insert( size_type index, const basic_string& str,
size_type index_str, size_type count = npos);
index位置插入常量str从index_str开始的count个字符,count可以表示的最大值为npos.这个函数不构成重载
npos表示一个常数,表示size_t的最大值,string的find函数如果未找到指定字符,返回的就是一个npos
|
string str1 = "meihao";
string str2 = "hello~";
string sstr = str2.insert(6,str1,3,string::npos);
cout<<sstr<<endl; //hello~hao
cout<<string::npos<<endl; //4294967295
|
iterator insert( iterator pos, CharT ch ); iterator insert( const_iterator pos, CharT ch ); |
string str1 = "meihao";
string::iterator it = str1.insert(str1.begin(),'a');
// string::iterator it = str1.insert(str1.cbegin(),'a'); //第二种
cout<<str1<<endl; //ameihao
cout<<*it<<endl; //a
|
void insert( iterator pos, size_type count, CharT ch ); 迭代器指向的pos位置插入count个字符ch |
string str1 = "meihao";
str1.insert(++str1.begin(),2,'a');
cout<<str1<<endl; //maaeihao
|
iterator insert( const_iterator pos, size_type count, CharT ch ); 迭代器指向的pos位置插入count个字符ch |
string str1 = "meihao";
string::iterator it = str1.insert(++str1.cbegin(),2,'a'); //和上面的可以混用
cout<<str1<<endl; //maaeihao
|
void insert( iterator pos, InputIt first, InputIt last );
iterator insert( const_iterator pos, InputIt first, InputIt last ); |
string str1 = "meihao";
string str2 = "hello";
//string::iterator it = str1.insert(str1.begin(),str2.begin(),str2.end());
string::iterator it = str1.insert(str1.begin(),std::begin(str2),std::end(str2));
cout<<str1<<endl; //hellomeihao
cout<<*it<<endl; //h
|
C++ string类insert用法总结的更多相关文章
- 标准C++中的string类的用法总结
标准C++中的string类的用法总结 相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的确,MFC中的CString类使用起来真的非常的方便好用.但是如果离开了MFC框架,还有 ...
- VC++ 标准C++中的string类的用法总结
相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的确,MFC中的CString类使用起来真的非常的方便好用.但是如果离开了MFC框架,还有没有这样使用起来非常方便的类呢?答案是肯 ...
- [C++][语言语法]标准C++中的string类的用法总结
转自:http://www.cnblogs.com/xFreedom/archive/2011/05/16/2048037.html 要想使用标准C++中string类,必须要包含 #include ...
- 标准C++中string类的用法
转自博客园:http://www.cnblogs.com/xFreedom/archive/2011/05/16/2048037.html 相信使用过MFC编程的朋友对CString这个类的印象应该非 ...
- 标准C++中的string类的用法总结(转)
http://www.cnblogs.com/xFreedom/archive/2011/05/16/2048037.html 相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的 ...
- 【C++】C++中的string类的用法总结
相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的确,MFC中的CString类使用起来真的非常的方便好用.但是如果离开了MFC框架,还有没有这样使用起来非常方便的类呢?答案是肯 ...
- string类的用法笔记
要想使用标准C++中string类,必须要包含 #include <string>// 注意是<string>,不是<string.h>,带.h的是C语言中的头文件 ...
- [转]标准C++中的string类的用法总结
原文地址:http://www.cnblogs.com/xFreedom/archive/2011/05/16/2048037.html 相信使用过MFC编程的朋友对CString这个类的印象应该非常 ...
- 标准C++中string类的用法总结
相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的确,MFC中的CString类使用起来真的非常的方便好用.但是如果离开了MFC框架,还有没有这样使用起来非常方便的类呢?答案是肯 ...
随机推荐
- vux的x-input的源码分析
<template> <div class="vux-x-input weui-cell" :class="{'weui-cell_warn': sho ...
- hibernate例子
首先下载好hibernate包 如果运行之后出现数据库连接错误 则重新把jar包位置放在web-inf的lib下面再addbulidpath 第一步:创建实体类 Hibernate要求实体类必须提供 ...
- 可访问范围 与 visual 或 abstract “修饰符”
protected:在当前类内定义,则在当前类“内部”可以调用,则在 派生子类"内部" 也可以调用 private,除去,在 派生子类"内部" 也可以调用,其它 ...
- Hibernate多对多单向关联和双向关联 --Hibernate框架
Hibernate关联关系中相对比较特殊的就是多对多关联,多对多关联与一对一关联和一对多关联不同,多对多关联需要另外一张映射表用于保存多对多映射信息.本例介绍多对多单向关联和双向关联.单向关联 :指具 ...
- LeetCode--014--最长公共前缀
问题描述: 编写一个函数来查找字符串数组中的最长公共前缀. 如果不存在公共前缀,返回空字符串 "". 示例 1: 输入: ["flower","flo ...
- android -------- 打开本地浏览器或指定浏览器加载,打电话,打开第三方app
开发中常常有打开本地浏览器加载url或者指定浏览器加载, 还有打开第三方app, 如 打开高德地图 百度地图等 在Android程序中我们可以通过发送隐式Intent来启动系统默认的浏览器. 如果手机 ...
- linux动态库
1.编写动态库函数接口 gcc -fPIC -shared -o libfunction.so funtion.c 2.写头文件 3.测试 gcc test.c -L. -lfuntion -o ru ...
- Luffy之虚拟环境.项目搭建,目录日志等配置信息
1. 项目开发前 1.1 虚拟环境virtualenv 如果在一台电脑上, 想开发多个不同的项目, 需要用到同一个包的不同版本, 如果使用上面的命令, 在同一个目录下安装或者更新, 新版本会覆盖以前的 ...
- 背包DP 存在异或条件的状态转移问题
题目链接 分析:有大佬说可以用线性基写,可惜我不会,这是用DP写的 题目明确说明可到达的位置只与能值有关,和下标无关,我们就可以排个序,这样每个数可以转移的区间就是它的所有后缀 我们可以用dp[i][ ...
- spring boot 2.0(一)权威发布spring boot2.0
Spring Boot2.0.0.RELEASE正式发布,在发布Spring Boot2.0的时候还出现一个小插曲,将Spring Boot2.0同步到Maven仓库的时候出现了错误,然后Spring ...