a = "Привет всем"; /* присваивание строки с завершающим нулем объекту */
с = а + " Георгий"; /* конкатенация объекта со строкой с завершающим нулем */
Следующая программа включает дополнительные определения операторов "=" и "+".
// Усовершенствование строкового класса.
#include <iostream>
#include <cstring>
using namespace std;
class str_type {
char string[80];
public:
str_type(char *str = "") { strcpy(string, str); }
str_type operator+(str_type str);
str_type operator+(char *str);
str_type operator=(str_type str);
str_type operator=(char *str);
void show_str() { cout << string; }
};
str_type str_type::operator+(str_type str)
{
str_type temp;
strcpy(temp.string, string);
strcat(temp.string, str.string);
return temp;
}
str_type str_type::operator=(str_type str)
{
strcpy(string, str.string);
return *this;
}
str_type str_type::operator=(char *str)