Guest User

Untitled

a guest
Aug 1st, 2012
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. How concatenate a string and a const char?
  2. string a = "hello ";
  3. const char *b = "world";
  4.  
  5. const char *C;
  6.  
  7. string a = "hello ";
  8. const char *b = "world";
  9. a += b;
  10. const char *C = a.c_str();
  11.  
  12. string a = "hello ";
  13. const char *b = "world";
  14. const char *C = (a + b).c_str();
  15.  
  16. #include <string>
  17. ///...
  18. std::string str="foo";
  19. std::string str2=str+" bar";
  20. str+="bar";
  21.  
  22. #include <sstream>
  23. //...
  24. std::string str1="hello";
  25. std::stringstream ss;
  26. ss << str1 << "foo" << ' ' << "bar" << 1234;
  27. std::string str=ss.str();
  28.  
  29. my_c_func(str1.c_str());
  30.  
  31. char *cp=std::malloc(str1.size()+1);
  32. std::copy(str1.begin(), str2.end(), cp);
  33. cp[str1.size()]='';
Advertisement
Add Comment
Please, Sign In to add comment