Advertisement
roysa99

hw_21_2_String.cpp

May 26th, 2013
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include "String.h"
  4. using namespace std;
  5.  
  6. String::String()
  7. {
  8.     length = 80;
  9.     str = new char[length+1];
  10.     str[0] = 0;
  11. }
  12.  
  13. String::String(int aLength)
  14. {
  15.     str = new char[aLength+1];
  16.     str[0] = 0;
  17. }
  18.  
  19. String::String(char *aStr)
  20. {
  21.     length = strlen(aStr);
  22.     str = new char[length+1];
  23.     strcpy(str, aStr);
  24. }
  25.  
  26. String::~String()
  27. {
  28.     delete[] str;
  29. }
  30.  
  31. void String::Print()
  32. {
  33.     cout << "\t" << str << "\n";
  34. }
  35.  
  36. void String::Read()
  37. {
  38.  
  39.     gets(str);
  40.     length = strlen(str);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement