fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iterator>
  4. #include <sstream>
  5. #include <array>
  6.  
  7. int main() {
  8. std::string test = "[1:2:3:4]cd/dvd PLDS DVD-RW DU8A6SH DU53 /dev/sr0";
  9.  
  10. std::array<int,4> v;
  11. char c;
  12. std::stringstream ss(test);
  13. ss >> c >> v[0] >> c >> v[1] >> c >> v[2] >> c >> v[3] >> c;
  14.  
  15. copy(begin(v), end(v), std::ostream_iterator<int>(std::cout, ", "));
  16. std::cout << "\n";
  17.  
  18. return 0;
  19. }
Success #stdin #stdout 0s 4560KB
stdin
Standard input is empty
stdout
1, 2, 3, 4,