Me: can we have modern C++?
Mom: we have modern C++ at home
Modern C++ at home:
1. const std::string str = "Modern C++";
2. std::string s1 {"Modern C++", 3};
3. std::string s2 {str, 3};
4.
5. std::cout << "S1: " << s1 << "\n";
6. std::cout << "S2: " << s2 << "\n";
Output:
S1: Mod
S2: ern C++
資料來源:
https://twitter.com/vzverovich/status/1345776339014488064
https://en.cppreference.com/w/cpp/string/basic_string/basic_string
s1 是用 (3) 建構式
basic_string( const basic_string& other,
size_type pos,
size_type count = std::basic_string::npos,
const Allocator& alloc = Allocator() );
s2 是用 (4) 建構式
basic_string( const CharT* s,
size_type count,
const Allocator& alloc = Allocator() );