+ 5
How to multiply ASCII in C++?
I want the result to be like this... @@@@@ So I so this.... cout << (char(64)) * 5; For some reason the result is printing stuff that I don't want. Anyone have an answer?
6 Answers
+ 6
Well, std::string has 9 constructors ( C++11 )
1 of them is a fill constructor which takes 2 arguments.
1: the size
2: the character
So std::string( 5, 64 ) then creates a string object of size 5, filled with @'s
std::string( 5, 64 ) = "@@@@@"
std::string( 7, '.' ) = "......."
int a = 6;
char b = '&';
std::string( a, b ) = "&&&&&&"
+ 4
You can use the std::string's fill constructor to 'multiply'.
std::string( amount to fill, char );
std::cout << std::string( 5, 64 );
+ 4
Dennis, can you explain that a little more?
+ 2
you need to create a function for that.