+ 9
Operators
can operators be overloaded to allow string and numeric concatenation?
14 Réponses
+ 12
Yes. I think this is possible. Just explicitly convert the numeric value to string, and concatenate it with the original string.
+ 4
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)
+ 1
Just fixed the link with url (%) encoding, sorry about that.
- 1
string s = string("hi") + 5;
What should s look like?
"hi5"?
"hi " 5 spaces?
Possible, but why?
- 1
yes it a matter of converting the numerical value to string .
- 1
Ostias, lo no sé tio :,v
- 1
Hello there I'm new here
- 1
I have questions
- 1
can you help me out
- 1
Alch no hablo inglés brow jsjsjajajaja
- 1
Posted in the machine
- 1
Tengo hambre
- 1
*Complete Achievements*
- 4
wow cool! Thanks Kirk!