What do I have to do so that when I
string s = ".";
If I do
cout << s * 2;
Will it be the same as
cout << "..";
?
What do I have to do so that when I
string s = ".";
If I do
cout << s * 2;
Will it be the same as
cout << "..";
?
They can't be multipled but I think you can write your own function to do this, something like -
It's probably not the best idea though, it will be very confusing to anyone looking at the code and not expecting this,
No,
std::string
has nooperator *
. You can add (char, string) to other string. Look at this http://en.cppreference.com/w/cpp/string/basic_stringAnd if you want this behaviour (no advice this) you can use something like this
http://liveworkspace.org/code/52f7877b88cd0fba4622fab885907313
There is no predefined
*
operator that will multiply a string by anint
, but you can define your own:std::string has a constructor of the form
that will repeat the character. For example
will output
Strings cannot be multiplied.
if s is a char
then
will give you