What are the differences in string initialization in C++?

前端 未结 4 1638
面向向阳花
面向向阳花 2021-02-04 01:53

Is there any difference between

std::string s1(\"foo\");

and

std::string s2 = \"foo\";

?

4条回答
  •  盖世英雄少女心
    2021-02-04 02:30

    The first one is better.

    The second one will create the instance and will assign the default value (""). Then there will be a secodn assignement : "foo". So 2 assignments instead of 1...

提交回复
热议问题