fork download
  1. #include <string>
  2. #include <vector>
  3. #include <iostream>
  4.  
  5. int main()
  6. {
  7. std::string num = "a string with 1000 characters";
  8. std::vector<std::string> myArray;
  9.  
  10. for ( unsigned int i = 0; i < num.length(); i += 5 )
  11. {
  12. myArray.push_back( num.substr( i, 5 ) );
  13. }
  14.  
  15. for ( unsigned int i = 0; i < myArray.size(); i++ )
  16. {
  17. std::cout << "Array[" << i << "] : " << myArray[i] << std::endl;
  18. }
  19. return 0;
  20. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
Array[0] : a str
Array[1] : ing w
Array[2] : ith 1
Array[3] : 000 c
Array[4] : harac
Array[5] : ters