append (STL Sample)
来源:互联网 发布:场矩阵布列松陈 编辑:程序博客网 时间:2024/06/05 05:19
basic_string::append (STL Sample)
The sample code below illustrates how to use the basic_string::append STL function in Visual C++.
Required Header:<string>
Prototype:
string& append(const basic_string& _X);
string& append(const basic_string& _X, size_type pos, size_type count);
string& append(const element_type *_S, size_type count);
string& append(const element_type *_S);
string& append(size_type count, element_type _C);
string& append(Iterator first, Iterator last);
Note: The class/parameter names in the prototype do not match the version in the header file. Some have been modified to improve readability.
Description:The append member functions of the basic_string append elements to the end of the string. The different forms of the function provide alternate ways to specify the source of the elements that will be appended. The append functions return a reference to the string to which the elements were appended.
Sample Code:
//////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// bsappend.cpp : Illustrates how to use the string append member
// function.
//
// Functions:
//
// string::append - appends a sequence of elements to the
// current string.
//////////////////////////////////////////////////////////////////////
#include <string>
#include <iostream>
using namespace std ;
void main()
{
string str1("012");
string str2("345");
cout << "str1 = " << str1.c_str() << endl;
// append str2 to str1
str1.append(str2);
cout << "str1 = " << str1.c_str() << endl;
// append the last 2 items in str2 to str1
str2 = "567";
str1.append(str2, 1, 2); // begin at pos 1, append 2 elements
cout << "str1 = " << str1.c_str() << endl;
// append the first 2 items from an array of the element type
char achTest[] = {'8', '9', 'A'};
str1.append(achTest, 2);
cout << "str1 = " << str1.c_str() << endl;
// append all of a string literal to str1
char szTest[] = "ABC";
str1.append(szTest);
cout << "str1 = " << str1.c_str() << endl;
// append one item of the element type
str1.append(1, 'D');
cout << "str1 = " << str1.c_str() << endl;
// append str2 to str1 using iterators
str2 = "EF";
str1.append (str2.begin(), str2.end());
cout << "str1 = " << str1.c_str() << endl;
}
Program Output is:
str1 = 012
str1 = 012345
str1 = 01234567
str1 = 0123456789
str1 = 0123456789ABC
str1 = 0123456789ABCD
str1 = 0123456789ABCDEF
Send feedback to MSDN. Look here for MSDN Online resources.
- append (STL Sample)
- stl string append函数
- find_first_of (STL Sample)
- size and resize (STL Sample)
- accumulate, copy, vector::push_back(STL Sample)
- Sample of STL(Vector):begin and rbegin
- Sample of STL(STL范例-容器部分)
- append
- append
- append
- append
- append
- sample
- !!!sample
- sample
- STL 源码分析之string(二)基础篇—append,reserve,assign
- Append Line
- 关于/*APPEND*/
- oracle练习及我的答案
- vs2005sp1补丁装不上解决办法
- 比较
- css优先级和!important与ie6的BUG
- 关键字:VC 自定义资源
- append (STL Sample)
- 更新自己的新浪围脖,大家有事就用这个练习哦~~
- ScriptManager.RegisterStartupScript()方法在ajax页面无效
- gdb查看内存
- 在 Android 中使用 SQLite, ContentProvider
- 在Winform 中拖动控件
- 该做什么样的选择
- oracle建立学生,课程以及选课表并进行插入查询操作
- accumulate, copy, vector::push_back(STL Sample)