Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include "stdafx.h"
- #include <stdio.h>
- #include <iostream>
- #include <conio.h>
- #include <string.h>
- #include <fstream>
- #include <math.h>
- #define SIZE 256
- using namespace std;
- class String
- {
- char* str1;
- char* str2;
- public:
- String();
- ~String();
- String(char*);
- char operator = (char*);
- void print();
- void set (char*);
- char* run();
- };
- String::String()
- {
- str1 = new char[SIZE];
- str1[0] = '\0';
- str2 = new char[SIZE];
- str2[0] = '\0';
- }
- String::String(char *inStr)
- {
- str1 = new char[strlen(inStr)];
- str1[0] = '\0';
- str2 = new char[strlen(inStr)];
- str2[0] = '\0';
- }
- String::~String()
- {
- delete[] str1;
- delete[] str2;
- }
- char* String::run()
- {
- char *subStr;
- if (strlen(str1)>12)
- {
- subStr = strchr(str1, ')');
- strcpy(str2, subStr);
- }
- else
- {
- strcpy(str2, str1);
- }
- return str2;
- };
- char String::operator = (char* str1)
- {
- strcpy(str2,str1);
- return *str2;
- }
- void String::set(char *inStr)
- {
- unsigned int i;
- for (i=0; i<strlen(inStr); i++)
- {
- str1[i] = inStr[i];
- }
- str1[i] = '\0';
- };
- void String::print()
- {
- cout<<str1<<endl;
- cout<<str2<<endl;
- }
- void main()
- {
- char inStr[256];
- cout<<"Input string: "<<endl;
- cin.getline(inStr, 256);
- String str;
- cout<<endl<<"Source & converted strings:"<<endl;
- str.set(inStr);
- ofstream file("text.txt",ios::out);
- file<<"sourse string: "<<inStr<<"\n"<<"converted string: "<<str.run()<<"\n";
- file.close();
- str.print();
- String *s1, *s2;
- s1 = new String();
- s2 = new String();
- s2->set(inStr);
- s1=s2;
- cout<<endl<<"String, copied using the overloading:"<<endl;
- s1->print();
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement