Creating file names automatically C++

前端 未结 5 1437
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-04 18:41

I\'m trying to write a program in C++, which creates some files (.txt) and writes down the result in them. The problem is that an amount of these files is not fixed at the begin

5条回答
  •  自闭症患者
    2021-02-04 19:07

     for(int i=0; i!=n; ++i) {
         //create name
         std::string name="file_" + std::to_string(i) + ".txt"; // C++11 for std::to_string 
         //create file
         std::ofstream file(name);
         //if not C++11 then std::ostream file(name.c_str());
         //then do with file
     }
    

提交回复
热议问题