fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <sstream>
  5. #include <cstring>
  6.  
  7. using namespace std;
  8.  
  9. void fill(std::vector<const char *> & vec, string str) {
  10. uint32_t start_count = 1;
  11. stringstream regname;
  12. for(uint32_t count = 0; count <= 3; count++) {
  13. regname.str("");
  14. regname << str << (uint32_t)(count + start_count);
  15. std::cout << "regname : " << regname.str() << std::endl;
  16. char * p = new char[regname.str().length() + 1];
  17. strcpy(p, regname.str().c_str());
  18. vec.push_back(p);
  19. }
  20. }
  21.  
  22. int main() {
  23. vector<const char *> vec;
  24. fill(vec, "temp");
  25.  
  26. for(int i = 0; i < vec.size(); i++)
  27. std::cout << "value at index : " << i << " is : " << vec[i] << std::endl;
  28. return 0;
  29. }
Success #stdin #stdout 0s 3236KB
stdin
Standard input is empty
stdout
regname : temp1
regname : temp2
regname : temp3
regname : temp4
value at index : 0 is  : temp1
value at index : 1 is  : temp2
value at index : 2 is  : temp3
value at index : 3 is  : temp4