std::string s1 {“Modern C++”, 3} vs std::string s1 {str, 3}

From:

https://en.cppreference.com/w/cpp/string/basic_string/basic_string

std::string s1 {"Modern C++", 3};

Uses the following constructor:

basic_string( const CharT* s,
          size_type count,
          const Allocator& alloc = Allocator() );

So takes 3 chars to get Mod.

std::string s2 {str, 3};

will use the following constructor:

basic_string( const basic_string& other,
          size_type pos,
          const Allocator& alloc = Allocator() );

So taking the string from position 3 onwards giving : ern C++.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)