Look at the following code...
#include <iostream>
#include <cstring>
using namespace std;
class string
{
char *p;
int len;
public:
string(char *);
void show()
{
cout<<p<<endl;
}
};
string :: string(char *p)
{
len = strlen(p);
this.p = new char[len+1];
strcpy(this.p, p);
}
int main()
{
string s1, s2;
char *nm1 = "IBM PC";
char *nm2 = "Apple computers";
s1 = string(nm1);
s2 = nm2;
s1.show();
s2.show();
char ch;
cin>>ch;
return 0;
}
In the above code everything is theoretically correct. But shows the following bug..
F:\Dev-Cpp\basic.cpp:18: error: `string' has not been declared