+ 2
The output is coming out to be an error...is that because the operation that i performed is illegal?
4 Antworten
+ 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;
+ 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++"
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