自考新教材--p54

烂漫一生 提交于 2019-12-06 08:38:34

源程序:

#include <iostream>

#include <cstring>

using namespace std;

int main()

{

string s1 = "c++语言";

string s2 = "程序设计";

string s3 = s1 + s2;

string s4;

s4 = s1.append(s2);

if (s3 == s4)

cout << "结果相同" << endl;

else

cout << "结果不相同" << endl;

int size = s1.size();

int length = s1.length();

cout << "size=" << size << "  ,length=" << length << endl;

s1[0] = 'J';

string s5 = s1.substr(3,4);

char str[20];

strcpy(str,s5.c_str);  //将s5中的字符串复制到str

cout << "str=" << str << endl;

cout << "s1=" << s1 << " ,s2=" << s2 << endl;

cout << "str=" << str << endl;

cout << "s2=" << s2 << endl;

cout << s2.find(str) << endl;

system("pause");

return 0;

}

 程序有错

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!