fstream file(FileName.c_str(), fstream::in), schema(SchemaName.c_str(), fstream::in); //objects used to open file and schema
if (file.is_open() && schema.is_open())
{
//reads all files
int FileLength, SchemaLength; //store length of file and schema
//buffer arrays that hold all characters in the file or schema
char* FileBuffer;
char* SchemaBuffer;
//finds length of file
file.seekg(ios::beg, ios::end);
FileLength = file.tellg();
file.seekg(ios::end, ios::beg);
//find length of schema
schema.seekg(ios::beg, ios::end);
SchemaLength = file.tellg();
schema.seekg(ios::end, ios::beg);
//creates arrays for file to be read into
FileBuffer = new char [FileLength];
SchemaBuffer = new char [SchemaLength];
file.read(FileBuffer, FileLength);
schema.read(SchemaBuffer, SchemaLength);
string FileBufferString = FileBuffer;
string SchemaBufferString = SchemaBuffer;
for (int a = 0; a < FileLength - (PositionName.length()+3); a++)
{
if (FileBufferString.compare(a, PositionString.length(), PositionString) > 0)
{
file.seekp(a + PositionName.length() + 3);
file << TagString.c_str();
file.flush();
}
}
for (int b = 0; b < SchemaLength - (PositionName.length()+29); b++)
{
if (SchemaBufferString.compare(b, SchemaPositionString.length(), SchemaPositionString) > 0)
{
schema.seekp(b + PositionName.length() + 29);
schema << SchemaTagString.c_str();
schema.flush();
}
}
//close files
file.close();
schema.close();
cout << endl << "Please check the files to ensure the program worked properly." << endl;
}
else
cout << "Cannot open the files.";
system ("PAUSE");
return 0;