inserting int variable in file name

c++

Solution

In C++11:

while(k<50){
  ifstream myfile("file_no_" + std::to_string(k) + ".vtk");
  // myfile << "data to write\n";
  k++;
}

Problem

Possible Duplicate: Easiest way to convert int to string in C++ 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++; } ```

Original source

Related problems