answersLogoWhite

0

There's no need to create a class to do this as std::string already does this and a lot more besides. The following class will do exactly as you've asked, but it's really just a wrapper for a std::string and achieves absolutely nothing.

#include<iostream>

class string{

public:

string(std::string s=""):m_str(s){}

string(const string& s):m_str(s.m_str){}

const std::string& get_string(){return(m_str);}

private:

std::string m_str;

};

int main()

{

string name1;

string name2("minu");

string name3(name2);

std::cout << "name1 = '" << name1.get_string().c_str() << "'" << std::endl;

std::cout << "name2 = '" << name2.get_string().c_str() << "'" << std::endl;

std::cout << "name3 = '" << name3.get_string().c_str() << "'" << std::endl;

return(0);

}

Output:

name1 = ''

name2 = 'minu'

name3 = 'minu'

User Avatar

Wiki User

12y ago

What else can I help you with?

Continue Learning about Engineering
Related Questions