我正在尝试在 C++ 中自动打开某些文件。文件标题相同,但文件编号不同。
像这样'test_1.txt test_3.txt test_6.txt ...'
这些数字未按常规顺序列出。
这是我的代码
`
#include <fstream>
#include <sstream>
#include <string>
#include <iostream>
using namespace std;
int main(){
int n[20]= {4,7,10,13,16,19,21,24,27,30,33,36,39,42,45,48,51,54,57,60};
ifstream fp;
ofstream fo;
fp.open(Form("test%d.txt",n));
char line[200];
if(fp == NULL)
{
cout << "No file" << endl;
return 0;
}
if(fp.is_open())
{
ofstream fout("c_text%d.txt",n);
while (fp.getline(line, sizeof(line)))
{
if(line[4] == '2' && line[6] == '4')
{
fout<<line<<"\n";
}
}
fout.close();
}
fp.close();
return 0;
}`
现在,函数“表单”不起作用。我没有其他想法。如果您有任何意见或想法,请告诉我。谢谢!