采用c++中的fstream对数据进行写入操作,保存为txt格式,代码编写如下,亲测可用:
#include#include #include #include using namespace std; int size = 9; unsigned long txtCount = 2; int main() { string txt_path = "out-data/"; string txt_name = txt_path + to_string(txtCount) + ".txt"; ofstream output_stream; //(txt_name) output_stream.open(txt_name); output_stream << "# index " << "n"; for(int i=0; i output_stream << std::to_string(i); output_stream << " "; output_stream << endl; } //txtCount = txtCount + 1; output_stream.close(); return 0; }
结果如下图所示:



