#include <stdio.h> //use of itoa: integer to char //puts output char* //convert string to char* //string name with accumulated acount. string sName = "book-"; int iCount; char cBuffer[3]; itoa(iCount, cBuffer, 10); if(iCount < 10) sName += "00"; if(iCount < 100) sName += "0"; if(iCount >= 1000) std::cerr << "no valid name index" << std::endl; sName += cBuffer; puts(sName .c_str() );
本文介绍了一个简单的C++程序示例,该程序利用itoa函数将整数转换为字符串,并将其附加到一个预定义的字符串上以创建类似于'book-001'这样的文件名。程序还包含了对生成字符串长度的检查。
2655

被折叠的 条评论
为什么被折叠?



