size and resize (STL Sample)
来源:互联网 发布:c 有网络编程吗 编辑:程序博客网 时间:2024/06/03 16:02
basic_string size and resize (STL Sample)
The sample code below illustrates how to use the basic_string size and resize STL functions in Visual C++.
Required Header:<string>
Prototype:
size_type size() const;
void resize(size_type n, E c = E());
resize is defined in header xstring which is included indirectly.
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 size function returns the length of the sequence. The resize function changes the size to the length specified by the first parameter. If the sequence is made longer, the function appends elements with the value of the second parameter. This value defaults to a null. The output of the sample code shows spaces for the null characters. operator<< reads the size of string and outputs each character in the string one at a time.
Sample Code:
//////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// <filename> : size.cpp
//
// Functions:
//
// size()
// resize() ; Defined in header xstring which is included indirectly.
//////////////////////////////////////////////////////////////////////
/* Compile options needed: /GX
*/
#include <iostream>
#include <string>
using namespace std;
void main()
{
string TestString = "1111122222333334444455555";
cout << TestString << "/n size: " << TestString.size() << endl;
TestString.resize(5);
cout << TestString << "/n size: " << TestString.size() << endl;
TestString.resize(10);
cout << TestString << "/n size: " << TestString.size() << endl;
TestString.resize(15,'6');
cout << TestString << "/n size: " << TestString.size() << endl;
}
Program Output is:
1111122222333334444455555
size: 25
11111
size: 5
11111
size: 10
11111 66666
size: 15
- size and resize (STL Sample)
- STL中vector的capacity、size、reserve、resize
- Sample of STL(Vector):begin and rbegin
- STL中容器的几个容易混淆的成员函数-size, capacity, resize, reserve
- STL中容器的几个容易混淆的成员函数-size, capacity, resize, reserve
- STL中容器的几个容易混淆的成员函数-size, capacity, resize, reserve
- Sample Size Determination
- calculate all controls size and position in the form when the form resize
- void QString::resize ( int size )
- vector size()/resize() reverse()/capacity()
- stl 容器 reserve resize
- stl vector resize reserve
- STL之resize()函数
- SAMPLE SIZE FOR SINGLE INSPECTION
- ffmpeg-resize and scale
- ffmpeg -resize and scale
- append (STL Sample)
- find_first_of (STL Sample)
- find_first_of (STL Sample)
- 正则表达式集
- VC与Python交互(一)(静态编译Python的方法)
- 显示隐藏控件的属性
- SP2010: SharePoint Microsoft Certified Master Program
- size and resize (STL Sample)
- amoeba------介于DB和客户端之间的代理
- Android UI 设计秘笈 :Part I
- ubuntu下安装mysql
- java3d简介
- 读取远程服务器的WMI,提示RPC服务器不可用
- C#发现之旅: WinForm.NET中开发具有固定背景图片的可滚动控件
- getopt 妙用
- lucene.net三种检索形式 备忘