string类的六种构造函数
来源:互联网 发布:软件评测师是什么 编辑:程序博客网 时间:2024/05/17 00:46
// stringctortest.cpp : 定义控制台应用程序的入口点。
//测试string类的六个构造方法
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string one("my first string test");
cout<<one<<endl;
string two(20,'@');
cout<<two<<endl;
string three(one,3);
cout<<three<<endl;
string four;
four=one+three;
cout<<four<<endl;
char a[]="It's a long way";
string five(a,10);
cout<<five<<endl;
string six(&one[0],&one[10]);
cout<<six<<endl;
return 0;
}
//测试string类的六个构造方法
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string one("my first string test");
cout<<one<<endl;
string two(20,'@');
cout<<two<<endl;
string three(one,3);
cout<<three<<endl;
string four;
four=one+three;
cout<<four<<endl;
char a[]="It's a long way";
string five(a,10);
cout<<five<<endl;
string six(&one[0],&one[10]);
cout<<six<<endl;
return 0;
}
上例中一共使用string类的六种构造函数。
第一个是赋给string对象one一个字符串。
第二个是赋给string对象two20个@符号。
第三个是将one从第三个位置开始到最后的字符赋给three。
第四个是创建一个没有值的默认的string对象。
第五个是将a指向的前10个字符赋给five。
第六个是将one的第一个至第十个字符赋给six。
其中第六个构造函数原型为:
template<class Iter>
string(Iter begin,Iter end)
即将string对象初始化为区间[begin,end]内的字符,其中begin和end的行为就像指针,用于指定位置,范围包括begin在内,但不包括end。
- string类的六种构造函数
- string类的七种构造函数
- string类的构造函数
- 类String的构造函数
- string类的构造函数
- string类的构造函数
- string 的构造函数
- String 类构造函数
- java中String类的构造函数
- java中String类的构造函数
- string类的构造函数实现
- c++ string类的构造函数
- C++ string类的构造函数
- string类的八个构造函数用法
- java中String类的构造函数
- C++基础---string类的构造函数
- C++ string类的构造函数
- Java中String类的构造函数
- vc 中的cfiledialog用法
- 时间类性之间的转换
- i2c子系统之platform_driver初始化——i2c_adap_s3c_init()
- Ubuntu10.04内核树的建立及其Hello World 模块的加载
- C++ vector的用法
- string类的六种构造函数
- 查询数据时是否使用LINQ的区别
- 判断ch中的字符是否与str所指串中的某个字符相同;若相同什么也不做。若不同,插在最后
- llvm基本概念
- Ubuntu 11.04安装pcsx2模拟器简明过程
- java反射机制
- Python_API_Structured Markup Processing Tools_sgmllib.SGMLParser.feed
- 2010 outlook导入QQ邮箱联系人
- 解决IE6不支持li:hover鼠标经过的效果