Is there a difference or is just a matter of preference? I'm a beginner to c++ and it bothers me that I am not confident that I'm choosing the right way to initialize a string value.
If I were to just choose one way which works for the vast majority of use cases, which would it be?
// Initializing from a literal. std::string s1{"hello"}; std::string s2("there"); std::string s3 = {"what"}; std::string s4 = "is"; // Initializing from another string object. std::string s5{s1}; std::string s6(s1); std::string s7 = s1; std::string s8 = {s1}; PS: Apologies if this question in it's entirety has been asked before, I couldn't find it anywhere and would appreciate it if someone could link to it here.