The program i am working on currently need to read a file and write into multiple files. Basically i am supposed to separate all the classes in tat file so i actually added an comment line to the file, i extract the classes according to the comments. Now i would like to write all the classes into different files,example test1.txt,tes2.txt,test3.txt.......this is my coding
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main ()
{
char str[99999];
char counter = '0';
string str2, str3, str4;
size_t pos, pos1;
fstream file_op("c:\\Fuse_cortex1.h",ios::in);
file_op.getline(str,99999,'@');
string s = str;
for(int i =0; i<40; i++)
{
if (counter == '0')
{
pos = s.find("//header#");
str2 = s.substr (pos);
pos1=str2.find("//header*");
str3 = str2.substr(0,pos1+9);
counter++;
fstream file_op1("c:\\header.txt",ios::out);
file_op1<<str3;
file_op1.close();
i++;
}
else
{
string start_temp = "//cls";
string end_temp = "//cls";
start_temp = start_temp + counter + "#";
end_temp = end_temp + counter + "*";
pos = s.find(start_temp);
str2 = s.substr (pos);
pos1=str2.find(end_temp);
str4 = str2.substr(0,pos1+8);
counter++;
/*tis is the part i need help*/ fstream file_op2("c:\\arun.txt",ios::out);
file_op2<<str4;
file_op2.close();
i++;
}
}
system("pause");
return 0;
}