本文简单介绍一下string最基本的功能
简单说明:
<string>
std::string line;//声明字符串line
line.size();//字符串长度
line.empty();//字符串是否为空
line[];//字符
string line = line1 +line2;
实例展示:
#include <string>
#include <iostream>
using namespace std;
int main()
{
//声明字符串对象
string line1,line2;
//string字符串输入
std::getline(cin, line1);
std::getline(cin, line2);
//效果展示
cout<<line1<<endl<<line2<<endl;;
//单个字符,起始地址为0
cout<<line1[1]<<endl;
//两字符串可连接
string line = line1 +line2;
string l = line1 + "+" +"\n"+line2;
cout<<"line:"<<endl<<line<<endl;
cout<<"l:"<<endl<<l<<endl;
//size为string的字符串长度函数(换行占一字符)
cout<<"line1.size()=" <<line1.size()<<endl;
cout<<