fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. int main() {
  7. const char src[] = "Hello, World!\0 Rise And shine!";
  8.  
  9. string s(src, sizeof(src));
  10.  
  11. cout << ">>> Length test:" << endl;
  12. cout << "sizeof(src): " << sizeof(src) << endl
  13. << "strlen(src): " << strlen(src) << endl
  14. << "s.length() : " << s.length() << endl;
  15.  
  16. cout << ">>> Output test:" << endl;
  17. cout << "src : \"" << src << "\"" << endl
  18. << "s.c_str(): \"" << s.c_str() << "\"" << endl
  19. << "s : \"" << s << "\"" << endl;
  20.  
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
>>> Length test:
sizeof(src): 31
strlen(src): 13
s.length() : 31
>>> Output test:
src      : "Hello, World!"
s.c_str(): "Hello, World!"
s        : "Hello, World! Rise And shine!"