Hello, I have to wirte this method and I'd like one efficent and compact:
int _low, _high;
std::string MyClass:: print() {
std::string str;
std::string result;
std::stringstream ss;
result += "[";
ss << _low;
ss >> str;
result += str;
result.append("-");
ss << _high;
ss >> str;
result += str;
result.append("]");
return result;
}
//main
MyClass mycl;
cout << " The range is: " << mycl.print() << endl
int _low, _high;
std::string MyClass:: print() {
std::string str;
std::string result;
std::stringstream ss;
result += "[";
ss << _low;
ss >> str;
result += str;
result.append("-");
ss << _high;
ss >> str;
result += str;
result.append("]");
return result;
}
//main
MyClass mycl;
cout << " The range is: " << mycl.print() << endl
To copy to clipboard, switch view to plain text mode
it must print: "the range is [10-20]"
It seems too large and not compact.... How can I improve?
Thanks.
Bookmarks