+ 2

In c++ what's my mistake when creating the code below?

int main() { int y =5; char x= "*"; cout<<y*x; return 0; }

3rd Sep 2018, 6:37 PM
Saeed Vahid
Saeed Vahid - avatar
12 odpowiedzi
+ 6
for char use single quotes ' ' for string use double quotes " "
3rd Sep 2018, 7:27 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 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; }
10th Sep 2018, 8:13 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 2
saeed sadeghi Vahid like how you want to repeat a string?
10th Sep 2018, 4:00 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 2
can you show an example of what you are saying?
10th Sep 2018, 5:41 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 2
I think that's pretty much it @ saeed
11th Sep 2018, 3:40 AM
Kingcharles
Kingcharles - avatar
+ 1
you can’t multiply a string by an integer
9th Sep 2018, 10:44 PM
Kingcharles
Kingcharles - avatar
+ 1
thank you all,specially nAutAxH AhmAd
12th Sep 2018, 11:16 AM
Saeed Vahid
Saeed Vahid - avatar
0
can we multiply a string or character by an integer?
5th Sep 2018, 1:54 PM
Saeed Vahid
Saeed Vahid - avatar
0
by operators or how it's possible.
10th Sep 2018, 4:53 PM
Saeed Vahid
Saeed Vahid - avatar
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?
10th Sep 2018, 6:39 PM
Saeed Vahid
Saeed Vahid - avatar
- 1
thanks,but if we want to repeat a string how we can code it? kingcharles
10th Sep 2018, 1:03 PM
Saeed Vahid
Saeed Vahid - avatar