如何将一个文件增加十倍?是否涉及 for(i = 0, i < 10, i++)。我遇到的大部分内容都是关于循环整数或打开多个不同的文件。我正在使用的代码如下。谢谢您的帮助。
const char *path="/Desktop/Libraries/Documents" ;
ofstream myfile(path);
myfile.open ("howyoulike.doc") ;
myfile << "How you like math\n" ;
myfile.close();
因此,我将代码编辑为:
const char *path="/Desktop/Libraries/Documents" ;
const char * FILENAMES[] ={"file1.doc", "file2.doc", "file3.doc", "file4.doc", "file5.doc"};
for (i = 0; i < 5; i++)
ofstream myfile(path);
myfile.open (FILENAMES[i]) ;
myfile << "How you like math?\n" ;
myfile.close();
现在我收到 c2228 错误“.open/.close 的左侧必须有类/结构/联合类型是未知类型”。有关如何修复的任何建议?
现在是我程序的一部分的可执行/运行代码。谢谢您的帮助!
#include <iostream>
#include <fstream>
using namespace std;
struct pizza{
string FILENAMES[9];
};
int main ()
{
int i;
pizza greg = {"file1.doc", "file2.doc", "file3.doc", "file4.doc", "file5.doc"};
cout << "Input is invalid. Program will end. " << "\n" ;
for (i = 0; i < 5; i++)
{
const char *path="/Desktop/Libraries/Documents" ;
ofstream myfile(path);
myfile.open (greg.FILENAMES[i]) ;
myfile << "How you like math?\n" ;
myfile.close();
};
return 0;
}