+ 2

The output is coming out to be an error...is that because the operation that i performed is illegal?

https://code.sololearn.com/c628l5R6xAln/?ref=app

22nd Aug 2018, 5:21 AM
riya
riya - avatar
3 ответов
+ 2
You are attempting to add an integer to a string using the operator ‘+’. To print your string and the integer 1, you would use cout << a << 1;
22nd Aug 2018, 5:31 AM
NULL
NULL - avatar
+ 2
Because there's no match for + operator when one operand is a string ( char sequence ) and other is an int constant. Technically, you are attempting to add this a: | I | | a | m | | l | e | a | r | n | i | n | g | | C | + | + | with this constant 1 So, how the heck should the compiler know what to do? On the other hand, picking one character from the char sequence and adding 1 to it isn't illegal at all. So, a[a.length() - 3] + 1; | I | | a | m | | l | e | a | r | n | i | n | g | | C | + | + | ^ +1 would turns the initial string to "I am learning D++"
22nd Aug 2018, 6:42 AM
Babak
Babak - avatar
0
this not a java comiler to add a string using + operator only this is possible in your code cout<<a<<1; then your output is i am a learning in c++1 thats it
22nd Aug 2018, 7:40 AM
Yash Soni
Yash Soni - avatar