fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <array>
  4.  
  5. int main()
  6. {
  7. std::string test = "[1:2:3:4]cd/dvd PLDS DVD-RW DU8A6SH DU53 /dev/sr0";
  8.  
  9. std::array<int, 4> arr; // or: int arr[4]; pre-C++11
  10. for(int i = 1, j = 0; i < 9; i += 2, ++j)
  11. arr[j] = test[i]-'0';
  12.  
  13. for(auto &s : arr)
  14. std::cout << s << std::endl;
  15.  
  16. return 0;
  17. }
Success #stdin #stdout 0s 4436KB
stdin
Standard input is empty
stdout
1
2
3
4