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

Untitled

By: a guest on May 15th, 2012  |  syntax: None  |  size: 0.62 KB  |  hits: 15  |  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 to pass variable in C   Sprintf 2nd(format) argument?
  2. string format = "what is your %s";  
  3. new_string = sprintf(buffer, format, name);
  4.        
  5. string format = "what is your %s";  
  6. int total = sprintf(buffer, format.c_str(), name);
  7.        
  8. std::ostringstream os;
  9. os << "what is your " << name;
  10. std::string new_string = os.str();
  11.        
  12. char buffer[100];
  13. string format = "what is your %s";
  14. sprintf(buffer, format.c_str(), name.c_str());
  15. string new_string(buffer);
  16.        
  17. stringstream buf;
  18. buf << "what is your " << name;
  19. string new_string = buf.str();
  20.        
  21. int len = sprintf(buffer, "what is your%s", name);
  22. std::string new_string(buffer, len);