在寫程序的過程中,對於數據結果的輸出需要針對研究對象命名,如果涉及到輸出的文件比較多,使用一個固定的字符串爲研究對象名字與結果類型拼接,這樣編程效率更高。
#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();
}
創建結果: