Tengo que hacer una clase que permite concatenar cadenas, luego de leer durante horas un libro de c++ me las arregle para hacer esto, compila perfecto en DEV C++ sin embargo cuando lo ejecuto me tira error y se me cierra, incluso hice copy & paste del programa del libro y tambien da error, aqui dejo lo que hice yo, es simple:
Código:
#ifndef STRING_H
#define STRING_H
#include <iostream>
using namespace std;
class Str
{
char string[100];
public:
Str(char s[] = "\0")
{
strcpy(string, s);
}
~Str() { };
Str operator +(Str);
Str operator =(Str);
void view();
};
#endif
string.cpp
Código:
#include "string.h"
#include <iostream>
Str Str::operator +(Str s)
{
Str tmp;
strcpy(tmp.string, string);
strcat(tmp.string, s.string);
return tmp;
}
Str Str::operator =(Str s)
{
strcpy(string, s.string);
return *this;
}
void Str::view()
{
cout << string;
}
main.cpp
Código:
#include "string.h"
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
Str str1("Hola "), str2("Mundo"), str3;
str3 = str1 + str2;
str3.view();
system("PAUSE");
return 0;
}
que esta mal???