String insert()总结
文件头格式
#include "stdafx.h"
#include <string>
#include <iostream>
int main( )
{
using namespace std;
}
-----------------------------------------------------------------
basic_string<CharType, Traits, Allocator>& insert(
size_type _P0,
const value_type* _Ptr
);
// 在 string 字符前(位置可以指定) 插入 char 类型字符串
basic_string <char> str1a ( "way" );
const char *cstr1a = "a";
str1a.insert ( 0, cstr1a ); // 0 可调整位置
cout << "The string with a C-string inserted at position 0 is: "
<< str1a << "." << endl;
// 结果 str1a = away.
-----------------------------------------------------------------
basic_string<CharType, Traits, Allocator>& insert(
size_type _P0,
const value_type* _Ptr,
size_type _Count
);
// 在 string 字符后插入指定长度的 char 类型字符
// 其中参数4代表原数据的长度
basic_string <char> str2a ( "Good" );
const char *cstr2a = "Bye Bye Baby";
str2a.insert ( 4, cstr2a ,3 ); // Good为4 , Bye为3
cout << "The string with a C-string inserted at the end is: "
<< str2a << "." << endl;
// 结果 str2a = GoodBye.
-----------------------------------------------------------------
basic_string<CharType, Traits, Allocator>& insert(
size_type _P0,
const basic_string<CharType, Traits, Allocator>& _Str
);
// 在 string 字符前(位置可以指定) 插入指定长度的 string 类型字符
basic_string <char> str3a ( "Bye" );
string str3b ( "Good" );
str3a.insert ( 0, str3b ); // 0 可调整位置
cout << "The string with a string inserted at position 0 is: "
<< str3a << "." << endl;
// 结果 str2a = GoodBye.
-----------------------------------------------------------------
basic_string<CharType, Traits, Allocator>& insert(
size_type _P0,
const basic_string<CharType, Traits, Allocator>& _Str,
size_type _Off,
size_type _Count
);
// 在 string 字符后插入指定长度的 char 类型字符 , 中间参数为过该字符串长度
// 起始点 并以该参数后的 第一个字符作为起始点 。插入第三个参数指定参数长度。
// 其中参数 5 代表原数据的长度
basic_string <char> str4a ( "Good " );
string str4b ( "Bye Bye Baby" );
str4a.insert ( 5, str4b , 8 , 4 ); // Bye Bye 为8 , Baby为4
cout << "The string with part of a string inserted at position 4 is: "
<< str4a << "." << endl;
// 结果 str2a = Good Baby.
-----------------------------------------------------------------
basic_string<CharType, Traits, Allocator>& insert(
size_type _P0, // 在原字符串后插入新字符串 po 代表参数 如:15
size_type _Count, // 在原字符串后插入新字符个数,且内容 为下面 _Ch 参数。
value_type _Ch // 在原字符串后面插内容参数 且 value_type 为 char
);
// 在指定位置 后插入指定个数的字符串。
string str5 ( "The number is: ." );
str5.insert ( 15 , 3 , '3' );
cout << "The string with characters inserted is: "
<< str5 << endl;
// 结果 The number is: 333.
-----------------------------------------------------------------
iterator insert(
iterator _It
);
iterator insert(
iterator _It,
value_type _Ch
)l
void insert(
iterator _It, // 指定原字符串内容 和 位置. 可参看 ( str6.begin ( ) + 4 ) 。
size_type _Count, // 指定新插入内容的个数
value_type _Ch // 新插入内容 参数。
);
// 在指定位置中插入 新字符 有个数参数
string str6 ( "ABCDFG" );
basic_string <char>::iterator str6_Iter = ( str6.begin ( ) + 4 ); // 在 string 字符串中第4位 插入 Ch 内容。且后面内容照旧。
str6.insert ( str6_Iter , 'e' );
cout << "The string with a character inserted is: "
<< str6 << endl;
// 结果 ABCDeFG
-----------------------------------------------------------------
template<class InputIterator> // template模板
void insert(
iterator _It, // 在迭代器后面字符插入内容。
InputIterator _First, // 输入迭代器, const_pointer ,或const_iterator处理中的第一个元素的来源范围内插入。
InputIterator _Last // 输入迭代器, const_pointer ,或const_iterator解决的立场,一个超越过去因素的来源范围内插入。
);
=================================================
void insert(
iterator _It, // 指定原字符串内容 和 位置. 可参看 (str7a.begin ( ) + 4 )
const_pointer _First, // 从要插入字符串的第一个元素往后数,到指定位置。 可参看 str7b.begin ( ) + 4
const_pointer _Last // 从要插入字符串的最后一个元素往前数,到指定位置。 可参看 str7b.end ( ) -1
);
// 在指定位置中插入新字符串。且指定范围。
string str7a ( "ABCDHIJ" );
string str7b ( "abcdefgh" );
basic_string <char>::iterator str7a_Iter = (str7a.begin ( ) + 4 );
str7a.insert ( str7a_Iter , str7b.begin ( ) + 4 , str7b.end ( ) -1 );
cout << "The string with a character inserted from a range is: "
<< str7a << endl;
// 结果 ABCDefgHIJ
-----------------------------------------------------------------
void insert(
iterator _It, // 指定原字符串内容 和 第一个元素往后数,到指定位置。. 可参看 (str7a.begin ( ) + 4 )
const_iterator _First, // 指定新插入内容的个数
const_iterator _Last // 新插入内容 参数。
);
// 在在指定位置中插入新字符。有个数参数
string str8 ( "ABCDHIJ" );
basic_string <char>::iterator str8_Iter = ( str8.begin ( ) + 4 );
str8.insert ( str8_Iter , 3 , 'e' );
cout << "The string with a character inserted from a range is: "
<< str8 << endl;
// 结果 ABCDeeeHIJ
=======================================================================
参数解释补充
_P0
该指数的作用是在最后点插入新的字符。
_Ptr
这架C -字串将全部或部分插入到字符串。
_Count
的字符数待补
_Str
该字符串将全部或部分插入到目标字符串。
_Off
该指数对部分供应源字符串的字符被附加。
_Ch
价值的性质的内容插入。
_It
一个迭代器处理的立场后面的字符是插入。
_First
输入迭代器, const_pointer ,或const_iterator处理中的第一个元素的来源范围内插入。
_Last
输入迭代器, const_pointer ,或const_iterator解决的立场,一个超越过去因素的来源范围内插入。
String insert()总结相关推荐
- json转string示例_C.示例中的String.Insert()方法
json转string示例 C#String.Insert()方法 (C# String.Insert() Method) String.Insert() method is used to inse ...
- c语言string函数的用法_同一个函数的五六个版本,C++string insert函数详解
前言 string 类的成员函数有很多,同一个名字的函数也常会有五六个重载的版本.篇幅所限,不能将这些原型一一列出并加以解释.这里仅对insert函数做以介绍,并直接给出应用的例子,通过例子,读者可以 ...
- c语言insert作用,C++string中的insert()插入函数详解
下面通过代码给大家介绍c++ string insert() 函数,具体内容如下: basic_string& insert (size_type pos, const basic_stri ...
- C++ string类的insert函数的介绍及使用
1.在特定位置插入const char *字符串 (1)string &insert(int p0, const char *s) 功能:在原字符串下标为pos的字符前插入字符串str 返回值 ...
- 标准C++中的string类的用法总结
相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的确,MFC中的CString类使用起来真的非常的方便好用.但是如果离开了MFC框架,还有没有这样使用起来非常方便的类呢?答案是肯 ...
- 转 C++STL之string
http://www.cnblogs.com/wangkangluo1/archive/2011/07/22/2114118.html string类的构造函数: string(const char ...
- 将表里的数据批量生成INSERT语句的存储过程 增强版
原文:将表里的数据批量生成INSERT语句的存储过程 增强版 将表里的数据批量生成INSERT语句的存储过程 增强版 有时候,我们需要将某个表里的数据全部或者根据查询条件导出来,迁移到另一个相同结构的 ...
- string类具体用法
string类具体用法 二话不说上代码 #include<string> #include<iostream> #include<algorithm> using ...
- 将表里的数据批量生成INSERT语句的存储过程 继续增强版
文章继续 桦仔兄的文章 将表里的数据批量生成INSERT语句的存储过程 增强版 继续增强... 本来打算将该内容回复于桦仔兄的文章的下面的,但是不知为何博客园就是不让提交!.... 所以在这里贴出来吧 ...
最新文章
- MySQL:互联网公司常用分库分表方案汇总!
- Java 9 CompletableFuture 进化小脚步
- atomic底层实现是基于无锁算法cas
- springcloud的config
- java inner static_Java SE Static Inner
- MySQL 排名函数.md
- java 改文件名的例子
- 主键与主键索引的关系
- 图像处理代码合集:特征提取-图像分割-分类-匹配-降噪
- windows如何安装codeblock
- IBus拼音无法选择候选词故障
- Mac下如何重启SSH
- windows文件隐藏之谜
- 海洋浮标在线监测系统由什么组成?
- c语言实现补码转换成原码,(转)C语言之原码、反码和补码(示例代码)
- ABP 临时禁用TenantId IsDelete过滤
- MSP432库函数学习笔记-CS
- 在phpstudy的环境下,如何配置php虚拟主机。
- NIM(1),转载自:雁过无痕
- excel隐藏列显示列操作
热门文章
- 1049-飞机最少换乘次数问题
- QTime使用中遇到的”not enough actual parameters for macro 'min'“问题
- 在 Mac 上多开微信,还能看到朋友撤回的信息:WeChatTweak
- 主从故障处理--session 级别参数复制错误
- 得到目标元素距离视口的距离以及元素自身的宽度与高度(用于浮层位置的动态改变)...
- 《软件建模与设计: UML、用例、模式和软件体系结构》一一
- 为什么 Linux的开发者要转到Windows 10 平台!
- 用property声明属性时,strong,copy,weak的一般用法
- Javascript中的0,false,null,undefined,空字符串对比
- 2011年3月华章新书书讯:ASP.NET本质论、Erlang编程指南、SNS网站构建