#include <iostream> #include <cstring> // using namespace std; class String { public: String() { } String(char* s) { length=sizeof(s)/sizeof(*s); _s=new char[length]; strcpy(_s,s); } std::ostream& operator<<(std::ostream& os) { for(int i=0;i<len;++i) os<<*(val._s+i); return os; } private: char* _s; int length; }; int main() { char str1[]="Hello World"; // std::cout << sizeof(s)/sizeof(*s) -1 << std::endl; //-1 for '\0' String str(str1); // std::cout<<str<<std::endl; return 0; }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more