+ 2
In c++ what's my mistake when creating the code below?
int main() { int y =5; char x= "*"; cout<<y*x; return 0; }
12 Réponses
+ 6
for char use single quotes ' '
for string use double quotes " "
+ 5
saeed sadeghi Vahid Here it is
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = "Hello ";
string str2 = "\0";
int num = 5;
for(int i = 0; i < num; i++)
str2 += str;
cout << str2 << endl;
return 0;
}
+ 2
saeed sadeghi Vahid like how you want to repeat a string?
+ 2
can you show an example of what you are saying?
+ 2
I think that's pretty much it @ saeed
+ 1
you can’t multiply a string by an integer
+ 1
thank you all,specially nAutAxH AhmAd
0
can we multiply a string or character by an integer?
0
by operators or how it's possible.
0
I want to take a number from user and print a word repeated by that number for example number is 5 And my word is hello ,I want it results as "hello hello hello hello hello" how can do it without multiplying operator?
- 1
thanks,but if we want to repeat a string how we can code it?
kingcharles