//12.2.ano.h
#ifndef STRING2_H_
#define STRING2_H_
#include
#include
using std::string;
using std::cout;
using std::cin;
using std::endl;
class String
{
private :
string str;
public :
String();
String(const string cs);
String(const String & s);
~String();
String & operator=(const String & s);
String & operator=(const string cs);
friend std::ostream & operator<<(std::ostream & os, String & s);
};
#endif
//string.cpp 实现文件
#include "12.2.h"
#include
String::String()
{
}
String::String(const string cs)
{
str = cs;
}
String::String(const String & s)
{
str = s.str;
}
String::~String()
{
}
String & String::operator=(const string cs)
{
str = cs;
return *this;
}
String & String::operator=(const String & s)
{
str = s.str;
return *this;
}
std::ostream & operator<<(std::ostream & os, String & s)
{
os << s.str;
return os;
}
//main.cpp 主函数
#include
#include "12.2.ano.h"
int main()
{
String a1 = "I know";
String a2 = (string)"I know";
cout << a1;
return 0;
}