string and int concatenation in C++ [duplicate]
问题 This question already has answers here : How to concatenate a std::string and an int? (23 answers) Closed 4 years ago . string words[5]; for (int i = 0; i < 5; ++i) { words[i] = "word" + i; } for (int i = 0; i < 5; ++i) { cout<<words[i]<<endl; } I expected result as : word1 . . word5 Bu it printed like this in console: word ord rd d Can someone tell me the reason for this. I am sure in java it will print as expected. 回答1: C++ is not Java. In C++, "word" + i is pointer arithmetic, it's not