|
1
2
3
4
|
Strings1,s2;s1="abc";s2=s1;s2="def"; |
|
1
2
3
4
5
6
|
stringa="hello,world!";stringb="hello,world!";stringc="hello!";stringa="hello,world!";stringb="hello,world!";stringc="hello!"; |
|
1
|
stringa="hello,world!"; |
|
1
2
|
00000042moveax,dwordptrds:[02A62208h]00000048movdwordptr[ebp-44h],eax |
|
1
|
stringb="hello,world!"; |
|
1
2
|
0000004bmoveax,dwordptrds:[02A62208h]00000051movdwordptr[ebp-48h],eax |
|
1
|
stringc="hello!"; |
|
1
2
|
00000054moveax,dwordptrds:[02A756F8h]0000005amovdwordptr[ebp-4Ch],eax |
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
string str;
cin >> str;
// int t=strlen(str);
cout<<str.length()<<endl;
cout<<str.begin()<<" "<<str[0]<<str[1]<<str[2]<<" "<<str.end()<<endl;
sort(str.begin(), str.end());
cout << str << endl;
return 0;
}相关函数:
| Constructors | 构造函数,用于字符串初始化 |
| Operators | 操作符,用于字符串比较和赋值 |
| append() | 在字符串的末尾添加文本 |
| assign() | 为字符串赋新值 |
| at() | 按给定索引值返回字符 |
| begin() | 返回一个迭代器,指向第一个字符 |
| c_str() | 将字符串以C字符数组的形式返回 |
| capacity() | 返回重新分配空间前的字符容量 |
| compare() | 比较两个字符串 |
| copy() | 将内容复制为一个字符数组 |
| data() | 返回内容的字符数组形式 |
| empty() | 如果字符串为空,返回真 |
| end() | 返回一个迭代器,指向字符串的末尾。(最后一个字符的下一个位置) |
| erase() | 删除字符 |
| find() | 在字符串中查找字符 |
| find_first_of() | 查找第一个与value中的某值相等的字符 |
| find_first_not_of() | 查找第一个与value中的所有值都不相等的字符 |
| find_last_of() | 查找最后一个与value中的某值相等的字符 |
| find_last_not_of() | 查找最后一个与value中的所有值都不相等的字符 |
| get_allocator() | 返回配置器 |
| insert() | 插入字符 |
| length() | 返回字符串的长度 |
| max_size() | 返回字符的最大可能个数 |
| rbegin() | 返回一个逆向迭代器,指向最后一个字符 |
| rend() | 返回一个逆向迭代器,指向第一个元素的前一个位置 |
| replace() | 替换字符 |
| reserve() | 保留一定容量以容纳字符串(设置capacity值) |
| resize() | 重新设置字符串的大小 |
| rfind() | 查找最后一个与value相等的字符(逆向查找) |
| size() | 返回字符串中字符的数量 |
| substr() | 返回某个子字符串 |
| swap() | 交换两个字符串的内容 |
原文地址:http://blog.csdn.net/u014492609/article/details/40298907