在写程序的过程中,对于数据结果的输出需要针对研究对象命名,如果涉及到输出的文件比较多,使用一个固定的字符串为研究对象名字与结果类型拼接,这样编程效率更高。
#include "pch.h"
#include <iostream>
# include <fstream>
#include<string.h>
using namespace std;
int main()
{
char object_name[100]= "hello world";//定义字符串
strcat_s(object_name, ".txt"); //两个字符串拼接
ofstream out(object_name); //创建文件名
out.close();
}
创建结果: