fork(1) download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. int main()
  7. {
  8. std::string test = "[1:2:3:4]cd/dvd PLDS DVD-RW DU8A6SH DU53 /dev/sr0";
  9.  
  10. std::string::size_type begin = test.find('[') + 1;
  11. std::string::size_type end = test.find(']', begin);
  12. std::string sub = test.substr(begin, end - begin);
  13.  
  14. std::vector<int> arr;
  15. std::istringstream iss(sub);
  16. int temp;
  17. while (iss >> temp) {
  18. arr.push_back(temp);
  19. iss.ignore();
  20. }
  21.  
  22. for(auto &s : arr)
  23. std::cout << s << std::endl;
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 4296KB
stdin
Standard input is empty
stdout
1
2
3
4