Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Str
- {
- public:
- Str();
- Str(int n);
- Str(char str[]);
- ~Str();
- void output();
- private:
- char* _str;
- int _n;
- };
- Str::Str()
- {
- _n = 0;
- _str = new char[_n];
- }
- Str::Str(int n)
- {
- _n = n;
- _str = new char[_n];
- }
- Str::Str(char str[])
- {
- int _n = strlen(str);
- _str = new char[_n];
- //strcpy(_str, str);
- for (int i = 0; i < _n; i ++)
- {
- _str[i] = str[i];
- }
- }
- void Str::output()
- {
- std::cout << _str << std::endl;
- }
- Str::~Str()
- {
- delete[] _str;
- }
- int main()
- {
- Str e;
- e.output();
- Str a;
- Str b(1);
- Str c("123");
- b.output();
- c.output();
- }
- Str::Str(const char * str)
- {
- _n = strlen(str) + 1;
- _n = 0;
- _str = new char[_n];
- #include <iostream>
- #include <iomanip>
- using namespace std;
- class Str
- {
- public:
- Str(size_t n = 1);
- Str(const char *str);
- ~Str();
- void output();
- private:
- char* _str;
- size_t _n;
- };
- Str::Str(size_t n)
- {
- _n = n;
- *(_str = new char[_n]) = 0;
- }
- Str::Str(const char *str)
- {
- _n = strlen(str)+1;
- _str = new char[_n];
- strcpy(_str, str);
- }
- void Str::output()
- {
- std::cout << _str << std::endl;
- }
- Str::~Str()
- {
- delete[] _str;
- }
- int main()
- {
- Str e;
- e.output();
- Str a;
- Str b(1);
- Str c("123");
- b.output();
- c.output();
- }
- Str::Str()
- {
- _n = 0;
- _str = NULL;
- }
- Str::Str(int n)
- {
- _n = n;
- _str = new char[_n + 1];
- _str[0] = '