+ 1

Why isn't it outputting int correctly?

I want it to work like: you input number and then it gives you "world 1; world 2; world 3; world n..." But for some reason it just outputs "world; orld; rld; ld; d;" https://code.sololearn.com/c69W87WqaOy2/?ref=app

6th Jun 2019, 6:18 PM
SummerWizard
SummerWizard - avatar
8 odpowiedzi
+ 2
Write << instead of +. A string literal is a pointer and when you add an int to it, it's like you use [i] with it.
6th Jun 2019, 6:26 PM
HonFu
HonFu - avatar
+ 2
Use your same code, but instead of i + "world", use to_string(i) + "world". Either that or use HonFu's method
6th Jun 2019, 6:28 PM
Trigger
Trigger - avatar
+ 1
No problem, SummerWizard👍🏼
6th Jun 2019, 6:31 PM
Trigger
Trigger - avatar
0
Use to_string(i)
6th Jun 2019, 6:25 PM
Trigger
Trigger - avatar
0
And start the loop from i = 1
6th Jun 2019, 6:25 PM
Trigger
Trigger - avatar
0
Thomas Williams, could you please expain how to use to_string(i), I've just started learning c++
6th Jun 2019, 6:27 PM
SummerWizard
SummerWizard - avatar
0
Thomas Williams thanks, the method above worked fine
6th Jun 2019, 6:30 PM
SummerWizard
SummerWizard - avatar