Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 1st, 2012  |  syntax: None  |  size: 0.64 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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()]='';