Operators | Sololearn: Learn to code for FREE!

+15

Operators

can operators be overloaded to allow string and numeric concatenation?

8/7/2017 12:07:00 AM

Karl

12 Answers

New Answer

+13

Yes. I think this is possible. Just explicitly convert the numeric value to string, and concatenate it with the original string.

+6

I looked into this when researching the 'endl' macro/ template (to show why newlines are faster than endl). All the operator overload options: http://en.cppreference.com/w/cpp/language/operators For one we've all seen, cout uses overloaded operators... see the definition for << (insertion): http://www.cplusplus.com/reference/ostream/ostream/operator%3C%3C/ (the %3C are for <<, otherwise SoloLearn breaks the link) Notice all the types it can handle. I believe you can make more by adding a new signature (and + is one of the 38 supported operators)

0

wow cool! Thanks Kirk!

0

Just fixed the link with url (%) encoding, sorry about that.

0

string s = string("hi") + 5; What should s look like? "hi5"? "hi " 5 spaces? Possible, but why?

0

yes it a matter of converting the numerical value to string .

0

Ostias, lo no sé tio :,v

0

Hello there I'm new here

0

I have questions

0

can you help me out

0

Alch no hablo inglés brow jsjsjajajaja

0

Posted in the machine