在文件名中插入int变量
问题描述:
可能重复:
在C ++中将int转换为字符串的最简单方法
如何在创建.vtk文件时插入int变量?我想要每k步创建文件。
ie所以应该有一系列文件,从file_no_1.vtk,file_no_2.vtk,...到file_no_49.vtk。
How can I insert int variable while creating .vtk file? I want to create file at every k step. i.e. so there should be series of files, starting from file_no_1.vtk, file_no_2.vtk, ... to file_no_49.vtk .
while(k<50){
ifstream myfile;
myfile.open("file_no_.vtk");
myfile.close();
k++;
}
答
while(k<50){
ifstream myfile("file_no_" + std::to_string(k) + ".vtk");
// myfile << "data to write\n";
k++;
}