fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. bool open_bracket = true;
  7. bool end = false;
  8.  
  9. size_t pos_open = 0;
  10. size_t pos_close = 0;
  11.  
  12. const char *dvar_hostname = "123[456]79[88]";
  13. string dh(dvar_hostname);//get string value
  14. while(!end){
  15. pos_open = dh.find('[');
  16. pos_close = dh.find(']');
  17.  
  18.  
  19. if(pos_open == string::npos || pos_close == string::npos || pos_close < pos_open){
  20. end = true;
  21. }else{
  22. dh.erase(pos_open, pos_close - pos_open + 1);
  23. }
  24. cout << pos_open <<endl;
  25. cout << pos_close <<endl;
  26. cout << dh <<endl;
  27. }
  28.  
  29. dvar_hostname = dh.c_str();//convert back
  30. cout << dvar_hostname;
  31. return 0;
  32. }
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
3
7
12379[88]
5
8
12379
4294967295
4294967295
12379
12379