
Untitled
By: a guest on
May 15th, 2012 | syntax:
None | size: 0.62 KB | hits: 15 | expires: Never
How to pass variable in C Sprintf 2nd(format) argument?
string format = "what is your %s";
new_string = sprintf(buffer, format, name);
string format = "what is your %s";
int total = sprintf(buffer, format.c_str(), name);
std::ostringstream os;
os << "what is your " << name;
std::string new_string = os.str();
char buffer[100];
string format = "what is your %s";
sprintf(buffer, format.c_str(), name.c_str());
string new_string(buffer);
stringstream buf;
buf << "what is your " << name;
string new_string = buf.str();
int len = sprintf(buffer, "what is your%s", name);
std::string new_string(buffer, len);