fork(4) download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class A{
  6. };
  7.  
  8. int main() {
  9.  
  10. // string::string(charT const* s)
  11. string s1("12345");
  12. // 5 - because constructor takes into account null-terminated character
  13. cout << s1.size() << endl;
  14.  
  15. // string(std::initializer_list<charT> ilist)
  16. string s2({'1','2','3','4','5'});
  17. // 5 - because string is built from the contents of the initializer list init.
  18. cout << s2.size()<<endl;
  19.  
  20. // string::string(charT const* s, size_type count)
  21. string s3("12345",3);
  22. // 3 - Constructs the string with the first count characters of character string pointed to by s
  23. cout << s3.size() << endl;
  24.  
  25. // basic_string( std::initializer_list<CharT> init,const Allocator& alloc = Allocator() ); - ?
  26. string s4({'1','2','3','4','5'},3);
  27. // 2 - why this compiles (with no warning) and what this result means?
  28. cout << s4.size() << endl;
  29.  
  30.  
  31.  
  32. string s5({'1','2','3','4','5'},5);
  33. // 0 - why this compiles (with no warning) and what this result means?
  34. cout << s5.size() << endl;
  35.  
  36. // basic_string( std::initializer_list<CharT> init,const Allocator& alloc = Allocator() );
  37. // doesn't compile, no known conversion for argument 2 from 'A' to 'const std::allocator<char>&'
  38. //string s6({'1','2','3','4','5'},A());
  39. //cout << s6.size() << endl;
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
5
5
3
2
0