Guest User

Untitled

a guest
May 15th, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  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);
Advertisement
Add Comment
Please, Sign In to add comment