20210531

六级-PRE | 计组-C1-1.2.3 | 实训C++相关

六级-PRE


计组-C1-1.2.3


实训C++相关

/*
string s1; //构造一个空的string类对象 s1
string s2="hello world"; //定义并初始化
string s3("hello world"); //用C语言格式字符串构造string类对象
string s4(10, 'a'); // 用10个字符'a'构造string对象s4
string s5(s2); //拷贝构造s5
string s6(s3,6); //用s3中下标为6开始的字符串构造string对象s6
*/
#include <iostream>
using namespace std;
int main()
{
int a = 49, b=49;
char c = 50;
string s1 = "haha";
string s2(s1);
string s3("hello world");
string s4(10, 'a');
string s5(s2);
string s6(s3,6);
cin >> c >> a >> b;
cout <<"hello world" << endl;
printf("a:%c,b:%c\n",a,b);
cout << "a:" << a << ",b:" << b << ",c:" << c << endl;
cout << s1 << endl;
cout << s2 << endl;
cout << s3 << endl;
cout << s4 << endl;
cout << s5 << endl;
cout << s6 << endl;
return 0;
}