According to this page, there are five ways to assign a string to a string:
string (1) string& operator= (const string& str); c-string (2) string& operator= (const char* s); character (3) string& operator= (char c); initializer list (4) string& operator= (initializer_list<char> il); move (5) string& operator= (string&& str) noexcept;
Then why should I compile the text below? Which of these parameters was used by the compiler?
#include <iostream> #include <string> int main() { std::string s; double d = 1.0; s = d; std::cout << s << std::endl; }
And this is not just a pointless question - I spent a lot of time trying to find this s = d
destination in my code. Of course, this should be s = std::to_string(d)
.
Compiler: GCC 4.8.4.
HEKTO source share