#include <iostream>
#include <cstdio> // 包含的头文件
using namespace std;
int main(int argc, char **argv)
{
int theTargetShapeForEncoding = 7;
int theParaLocationInformation = 5;
char aCharFormat[2]; // 注意声明变量的大小,最好不要太小,如果为 1 的话, 那么是会出错的。 详细的请参考下面的函数解释。
//char aCharFormat[1]; // 如果声明为 1 , 那么后面的 std::cout ... 输出是空。
snprintf(aCharFormat, sizeof(aCharFormat), "%x", theTargetShapeForEncoding);
std::cout << "XXXX aCharFormat = " << aCharFormat << std::endl;
snprintf(aCharFormat, sizeof(aCharFormat), "%x", theParaLocationInformation);
std::cout << "XXXX aCharFormat = " << aCharFormat << std::endl;
return 0;
}
头文件: #include <cstdio>
snprintf 函数原型: int snprintf(char *str, size_t size, const char *format, ...)
详解:
原文:http://www.cnblogs.com/AndyStudy/p/5819145.html