String insert()总结
来源:互联网 发布:抢火车票软件下载 编辑:程序博客网 时间:2024/05/22 08:18
文件头格式
#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()总结
- insert select string[,]
- String insert() 插入方法
- String insert() 插入方法
- C# string insert
- string insert()函数的用法
- C++ string类insert函数
- insert用法总结
- oracle insert 总结
- SQL---DML---INSERT---INSERT语句总结
- hibernate insert sqlsever 问题总结
- Question2Answer mysql insert eventlog utf8_encode ( string $data )
- C++基础---string类的insert
- string的插入与删除insert、erase
- String总结
- string 总结
- String总结
- String总结
- Math.min.apply数组排序
- JS中的完美运动框架
- 使用反汇编理解动态库函数调用方式GOT/PLT
- Attribute is missing the Android namespace prefix 错误总结 .
- Junit4的使用
- String insert()总结
- 中文分词综述
- 在ios上input标签不能失去焦点
- <转> linux下的tar使用
- PageHelper 实现原理
- 三大框架核心包以及作用
- jquery each,grap遍历方法
- 最小生成树(普利姆算法、克鲁斯卡尔算法)
- C#入门5.6——迭代语句之for语句