+ 13
About cout
Cout<< 1+"hello"; Why the output is "ello"? Cout<<2+ "hello"; Why the output is "llo"? Why do we see only the pieces of the word "hello"? What does cout return with numbers?
20 odpowiedzi
+ 22
Strings are arrays of characters. And arrays are implemented with pointers. Which means that what you do here is add 1 or 2 to the address of the array, and since sizeof(char) is 1, you will skip as many characters.
+ 5
Additionally, this approach will not work if you use it directly on a std::string object, because it is more than a simple char array. However, the same effect is possible through the use of the `c_str` or `data` member of the std::string object, which exposes the internal buffer content.
+ 5
~ swim ~ That's right 👍
But we can't do that on the string object, only with the .c_str or .data which exposes the internal buffer : )
+ 5
Though I could've been more clear if I said "this will not work if you use a std::string object directly, ..."
I will make adjustment on my first post, Thanks ~ swim ~ for the note 😁
+ 3
If you added the 1+ at the beginning or end of the string (ex. cout << 1+"hello"), it returns "ello" because the 1+ removes a letter from the beginning of the string. The second experiment you made has removed 2 letters from the beginning of the string.
So, the output will be a whole string, but a number of characters at the beginning of the string will be removed.
0
What is string object
0
Привет
0
Есть русский
0
I think you need to write " in front of 1, i try it and works
0
Hello
0
Разобрался?
0
Right answer:
cout<<1<<"hello";
0
Hello
0
По
0
Hlo sir
0
Hey how to learn programming may i ask anyone who can me
0
Helo . How to make game and launch on playstore
0
cout <<"my name is mohamed Mostafa I need learn C++" ;
0
I love C++ programeble
0
Gay