fork download
  1. #include <cstring>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. void TransformString(const char *in_c_string, char *out_c_string) {
  6. size_t length = strlen(in_c_string);
  7.  
  8. for (size_t i = 0; i < length; ++i)
  9. out_c_string[i] = '*';
  10.  
  11. out_c_string[length] = 'a';
  12. out_c_string[length+1] = 'b';
  13. out_c_string[length+2] = 'c';
  14. out_c_string[length+3] = '\0';
  15. }
  16.  
  17. std::string TransformString(const std::string &in_string) {
  18. std::string out;
  19. out.resize(100);
  20.  
  21. TransformString(in_string.c_str(), &out[0]);
  22.  
  23. out.resize(strlen(&out[0]));
  24.  
  25. // IIRC there are some C++11 rule that allow 'out' to be moved here (if it isn't RVO'd anyway)
  26. return out;
  27. }
  28.  
  29. int main() {
  30. std::string string_out = TransformString("hello world");
  31.  
  32. char charstar_out[100];
  33. TransformString("hello world", charstar_out);
  34.  
  35. std::cout << string_out << "\n";
  36. std::cout << charstar_out << "\n";
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
***********abc
***********abc