我想知道是否有可能以及如何在C++ crossplatform中实现(C99,C++ 0x独立)snprintf?有没有这样的提升?(我想知道要替换的C++习语是snprintf(4)什么?)
std::ostringstream将是一个使用的替代snprintf:
char buf[1024];
snprintf(buf, 1024, "%d%s", 4, "hello");
Run Code Online (Sandbox Code Playgroud)
当量:
#include <sstream>
std::ostringstream s;
s << 4 << "hello";
// s.str().c_str(); // This returns `const char*` to constructed string.
Run Code Online (Sandbox Code Playgroud)
std::string s = boost::lexical_cast<std::string>(4) +
boost::lexical_cast<std::string>("hello");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1026 次 |
| 最近记录: |