fork(1) download
  1. #include <iostream>
  2. class S{
  3. public:
  4. char c[99999];
  5.  
  6. S(){
  7. c[0] = 0;
  8. }
  9.  
  10. S(char s){
  11. c[0] = s;
  12. c[1] = 0;
  13. }
  14.  
  15. S(const char * s){
  16. int k = 0;
  17. while(k > -1)
  18. {
  19. if (s[k] != 0)
  20. {
  21. c[k] = s[k];
  22. k+=1;
  23. }
  24. else
  25. {
  26. c[k] = s[k];
  27. k = -2;
  28. }
  29.  
  30. }
  31. }
  32. S(const S& s){
  33. for(int i = 0; i < 99999; i++)
  34. {
  35. c[i] = s.c[i];
  36. }
  37. }
  38. S& operator=(const S& s) {
  39. for(int i = 0; i < 99999; i++)
  40. {
  41. c[i] = s.c[i];
  42. }
  43. return *this;
  44. }
  45. int length() const{
  46. int q = 0;
  47.  
  48. while(q > -1)
  49. {
  50. if (c[q] == 0)
  51. {
  52. return q;
  53. }
  54. else
  55. {
  56. q++;
  57. }
  58. }
  59. }
  60. S& operator+=(const S& s1){
  61. int t = length();
  62. for(int i = t; i < (t + s1.length()); i++)
  63. {
  64. c[i] = s1.c[(i - t)];
  65. }
  66. c[t + s1.length()] = 0;
  67. return *this;
  68. }
  69. const S operator+(const S& s1){
  70.  
  71. int t = length();
  72. S tmr(c);
  73.  
  74. for(int i = t; i < (t + s1.length()); i++)
  75. {
  76. tmr.c[i] = s1.c[(i - t)];
  77. }
  78. tmr.c[t + s1.length()] = 0;
  79. return tmr;
  80. }
  81. char operator[](int n){
  82. return c[n];
  83. }
  84. const char operator[](int n) const{
  85. return c[n];
  86. }
  87.  
  88. friend std::ostream& operator<<(std::ostream& os, const S& value)
  89. {
  90. os << value.c;
  91. return os;
  92. }
  93. const char* str() const {
  94. return (const char *) c;
  95. }
  96. };
  97.  
  98. int main(){
  99. char a;
  100. S s("qwerty");
  101. int i = 1;
  102. std::cout << s[i] << ' ' << s[2];
  103. std::cin >> a;
  104. return 0;
  105. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
w e