/*
*C++字符串中的各种函数
*/
#include <iostream>
using namespace std;
#include <string>
int main()
{
/*
//调用字符串的构造函数初始化
//1、string(); 构造一个空串
string str1;
cout << "str1=" << str1 << endl;
//2、string( const char *str );
//以str所指向的字符串初始化
string str2("zhou");
cout << "str2=" << str2 << endl;
//3、string( size_type length, char ch );
//以length长度的字符 ch 初始化【拷贝】
string str3(5,'J');
cout << "str3=" << str3 << endl;
//4、string( const char *str, size_type length );
//以字符串前length 长度的子串初始化
string str4("No pain No gain!",6);
cout << "str4=" << str4 << endl;
//5、string( string &str, size_type index, size_type length );
//以index为索引开始的子串,长度为length
string str5("Love is pain!",4,6);
cout << "str5=" << str5 << endl;
//6、string( input_iterator start, input_iterator end );
//使用容器和迭代器
*/
string str1("Faith Persist Perseverance");
string str2("Sweet Baby");
//cout << sizeof(string) << ',' << sizeof(str1) << endl;
//字符串长度
//size_type size();
//该函数求得字符串中现在拥有的字符数
cout << "str1.size()的长度:" << str1.size() << endl;
cout << "str2.size()的长度:" << str2.size() << endl;
/*//size_type length();
//字符串的长度
cout << "str1.length()的长度:" << str1.length() << endl;
cout << "str2.length()的长度:" << str2.length() << endl;
//size_type max_size();
//字符串所能保存的最大字符个数
cout << str1.max_size() << endl;*/
int size = (str1.size() < str2.size())?str1.size():str2.size();
int i = 0;
//判断字符串的大小(ASCII值的比较)
for(i = 0; i != size; i++)
{
if(str1[i] > str2[i])
cout << '-' << str1[i];
}
cout << endl;
for(i = 0; i != size; i++)
{
if(str1[i] < str2[i])
cout << str2[i] << '-';
}
cout << endl;
for(i = 0; i != size; i++)
{
if(str1[i] < str2[i])
cout << str2[i] << '-';
}
cout << endl;
return 0;
}