1. read the program and give the running result
#include <string>
#include <iostream>
using namespace std;
int main()
{
string a("abc");//创建字符串a
string b("StringB");
cout <<"Length of a=" <<a.length() <<endl;//此时a 的长度为3
cout <<a <<endl;//字符串a 的内容为“abc”
a.append("EFG");//在字符串末尾添加“EFG”
cout <<"Length of a=" <<a.length() <<endl;//此时字符串长度为6
cout <<a <<endl;//字符串a 的内容为“abcEFG”
a.insert(3,b);//在字符串a 的第三个字符后插入字符串b
cout <<a <<endl;//字符串a 的内容为“abcStringBEFG”
cout <<a.compare("ABCDEFG") <<endl;//字符串a 与“ABCDEFG”比较,不同应输出1
cout <<a.compare(a) <<endl;//字符串a 与自己比较,相同应输出0
cout <<a.empty() <<endl;//字符串a 不是空的,应输出0
a.swap(b);//字符串a 和b 内容交换
cout <<"String a is "<<a <<endl <<"String b is "<<b <<endl;
return 0;
}
2. read the program and give the running result
#include<iostream>
using namespace std;
int main()
{
int sum = 0;
for(int i=1; i<=100;i++)
{
if(i>50)
break;
if(i%3==0)
continue;
sum += i;
}
cout << sum << endl;
return 0;
}
3. Write a program that contains four arrays. Three of the arrays should contain your first name, middle initial, and last name. Use the string-copying function to copy these strings together into the fourth array, full name.