c++ - Why I cannot do 'cout << 3*" ";'? -
why cannot
cout << 3*" ";
error:
e:\c++\test\main.cpp|12|error: invalid operands of types 'int.' , 'const char [2]' binary 'operator*'
some languages allow multiplication operator used in way. instance python allows write:
3*" "
and evaluates as
" "
but c++ not allow use of multiplication operator. precisely compilation error telling you.
you attempting create string contains 3 spaces. this, example, using fill constructor of standard string class:
std::string(3, ' ')
and send cout
:
std::cout << std::string(3, ' ');
Comments
Post a Comment