Customize the file name and saving directory

来源:互联网 发布:大数据降维 编辑:程序博客网 时间:2024/05/21 10:34

Some fragments of code for customizing the file name and saving directory.


Customizing the file name with index:

//Output the customized files into specified folderchar directory[15] = "cells";char fp[20];int cell_id = 1;//Specify the file name with index: "cell_id" in this caseint n = std::sprintf(fp, ".\\%s\\cell%d.obj", directory, cell_id);FILE *fn = fopen(fp, "w");//necessary operations for writing data into output filefclose(fn);


 Another way is to use stringstream to cumtomize string variable:

sample code

#include <iostream>using namespace std;#include <sstream>#include <string>int main(){stringstream outstream;int i;i = 1;outstream << "subclass_" << i << ".obj";string filename = outstream.str();cout << filename << endl;return 0;}




 

原创粉丝点击