std::string::assign vs std::string::operator=
问题 I coded in Borland C++ ages ago, and now I'm trying to understand the "new"(to me) C+11 (I know, we're in 2015, there's a c+14 ... but I'm working on an C++11 project) Now I have several ways to assign a value to a string. #include <iostream> #include <string> int main () { std::string test1; std::string test2; test1 = "Hello World"; test2.assign("Hello again"); std::cout << test1 << std::endl << test2; return 0; } They both work. I learned from http://www.cplusplus.com/reference/string