Is it possible to multiply a char by an int?
For example, I am trying to make a graph, with *’s for each time a number occurs.
So something like, but this doesn’t work
char star = "*";
int num = 7;
cout << star * num //to output 7 stars
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I wouldn’t call that operation “multiplication”, that’s just confusing. Concatenation is a better word.
In any case, the C++ standard string class, named
std::string, has a constructor that’s perfect for you.Content is initialized as a string formed by a repetition of character
c,ntimes.So you can go like this:
Make sure to include the relevant header,
<string>.