fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main() {
  7. vector<unsigned char> some_vector{ 'H', 'e', 'l', 'l', 'o' };
  8. size_t i = 0;
  9. size_t j = 5;
  10.  
  11. // using a char* pointer and a size...
  12. std::string tmp1( reinterpret_cast<char*>(&some_vector[i]), j-i );
  13. cout << tmp1 << endl;
  14.  
  15. // using char* pointers as iterators...
  16. std::string tmp2( &some_vector[i], &some_vector[j] );
  17. cout << tmp2 << endl;
  18.  
  19. // using vector iterators...
  20. std::string tmp3( some_vector.begin()+i, some_vector.begin()+j );
  21. cout << tmp3 << endl;
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 4532KB
stdin
Standard input is empty
stdout
Hello
Hello
Hello