【发布时间】:2015-08-28 22:59:22
【问题描述】:
我正在尝试根据与文件名关联的数字来增加文件名。如果我将变量 postFix 设为 int 类型,它会给出错误(可以理解),因为我无法将 int 连接到字符串类型。
在这种情况下如何增加字符串变量?
for (int i = 0; i <= 10; i++)
{
std::string postFix = "1"; // int postFix = 1 gives an error
std::cout << (std::string("Image" + postFix + std::string(".png")));
}
【问题讨论】:
-
请澄清“递增”字符串变量。字符串递增后的值是多少?如果我有字符串“hello”,它增加后会发生什么?
-
另一个建议,您可以通过在文件名中添加时间戳来使文件名唯一。
-
@ThomasMatthews 我想将 postFix 值从 1 增加到 2 到 3 到.. 20 作为循环结束。