string实现两个字符串的连接
2007-10-03 20:13
288 查看
//用string类型的字符串连接两个字符串。
//string比c风格好用!因为C++封装了字符串,把字符串的所有操作封装在string类中
#include<iostream>
#include<string>
using namespace std;
int main()
{
const string str1("I am a hardwork ");
cout<<str1<<endl;
const string str2("student");
cout<<str2<<endl;
string result_str=str1;
result_str+=str2;
cout<<result_str<<endl;
return 0;
}
//string比c风格好用!因为C++封装了字符串,把字符串的所有操作封装在string类中
#include<iostream>
#include<string>
using namespace std;
int main()
{
const string str1("I am a hardwork ");
cout<<str1<<endl;
const string str2("student");
cout<<str2<<endl;
string result_str=str1;
result_str+=str2;
cout<<result_str<<endl;
return 0;
}
相关文章推荐
- 不调用C库函数string.h实现字符串的连接
- 数组实现两个字符串的连接
- 6-2-1 字符串-字符串变量String-创建字符串变量-初始化字符串变量-字符串连接-输入字符串(单词、行)-对象变量的赋值-比较两个字符串是否同一个-比较两个字符串内容是否相同
- C语言 不使用strcat函数实现连接两个字符串功能
- 编写一个函数,实现两个字符串的连接功能
- c++ 连接两个字符串,实现类似strcat 功能
- 编一程序,将两个字符串连接起来,即实现strcat函数功能
- 问题一:编写函数stringcat,实现字符串的连接,程序中需要使用指针形式访问字符串
- 问题九:编写函数stringcat,实现字符串的连接,程序中需要使用指针形式访问字符串
- 实现一个字符串类,可以比较和连接两个字符串
- c++ 连接两个字符串实现代码 实现类似strcat功能(转)
- 将两个字符串连接起来 用string
- 实现两个字符串的连接(strcat函数)
- Python实现string字符串连接的方法总结【8种方式】
- 将两个字符串连接起来取代第一个字符串。用string方法
- 书上实现连接两个字符串的代码,分享下!
- Javascript扩展String.prototype实现格式金额、格式时间、字符串连接、计算长度、是否包含、日期计算等功能
- JavaSE8基础 String concat与+ 连接两个字符串
- buctoj-1031 String 和StringBuffer 实现输入字符串反转输出功能