Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Compile and Execute C++11 Online

#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;
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.