需求如下:
实现代码通过下面main函数中的测试用例
#include<iostream>
using namespace std;
#include <vector>
class String
{
friend ostream& operator<<(ostream& out, const String& str);
public:
String(const char *str = 0);// 普通构造函数
String(const String &other); // 拷贝构造函数
~String(void);
String& operator=(const String &other);// 赋值函数
char* data(void) const { return data_; }
private:
ostream& Print(ostream& out) const; char *data_; // 用于保存字符串
};
void f(const String& s)
{
std::cout << s << endl;
}
void g(std::vector<String> stringList)
{
for (auto i : stringList)
{
std::cout << i << endl;
}
}
void main()
{
std::vector<String> stringList;
char* p = "Hello World !";
String s(p);
for (size_t i = 0; i < 15; i++)
{
stringList.push_back(s);
}
cout << s << endl;
String s1("How are you ?");
cout << s1 << endl;
s1 = s;
cout << s << endl << s1 << endl;
s = s = s1;
cout << s << endl << s1 << endl;
f(s);
g(stringList);
}
正确输出:
答案:企业微信文件盘