snprintf头文件在stdio.h里,参数为char* 、size、format、argus
代码实例如下:
#include <cstdio>
#include <iostream>
using std::cout;
using std::endl;
int main() {
char conf_path[1024];
cout << "conf_path size: " << sizeof(conf_path) << endl;
int ret = snprintf(conf_path, sizeof(conf_path), "%s", "./conf");
cout << "ret: " << ret << endl;
cout << "conf_path: " << conf_path << endl;
return 0;
}
输出: