Files
Avancerad_CPP/Lab6/str.cpp
2026-03-05 13:16:26 +01:00

73 lines
949 B
C++

#include <iostream.h>
#include <string.h>
#include "Str.h"
Str::Str():curPos(0){
str = new char[200];
}
Str::Str(char* _str){
str = new char[200];
strcpy(str, _str);
}
Str::~Str(){
delete [] str;
}
bool Str::operator==(Str &src){
if(strcmp(src.getStr(), getStr()) == 0)
return true;
return false;
}
Str::Str(const Str& src)
{
str = new char [strlen(src.str)+1] ;
strcpy(str,src.str);
}
Str& Str::operator =(const Str &src){
if(this!= &src)
{
delete [] str;
str = new char [strlen(src.str)+1] ;
strcpy(str,src.str);
}
return *this;
}
istream& operator >> (istream& is, Str &s){
char t,x;
do{
if(is.peek() != '\n'){
t = is.get();
s.str[s.curPos++] = t;
}
else
x= is.get();
}while(is.peek() != '\n');
s.str[s.curPos] = NULL;
return is;
}