Ok so the programming is working great. I got around all my issues. However, I am now looking for a way for the program to check the lines in "newline.txt" and see if they are duplicates of the ones in the output file and if so, do not copy them. Any suggestions?
Code:
//
#include <fstream>
#include <iostream>
#include <string>
#include <stdio.h>
#include <Windows.h>
int main()
{
int results;
char oldname[] = "c:\\synergyii\\config\\clientconfig.xml";
char newname[] = "c:\\synergyii\\config\\clientconfig.txt";
results = rename(oldname, newname);
if (results == 0)
puts("File successfully renamed");
else
perror("Error renaming file");
std::ifstream inf{ "c:\\synergyii\\config\\clientconfig.txt" };
std::ofstream outf{ "c:\\synergyii\\config\\clientconfig.xml" };
if (!inf)
{
std::cerr << "Cannot open client config for reading" << std::endl;
return 1;
}
if (!outf)
{
std::cerr << "Cannot open client config for writing" << std::endl;
return 1;
}
std::string line{ "</settings>" };
std::string strInput;
while (std::getline(inf, strInput))
{
if (strInput == line)
{
break;
}
else
{
outf << strInput << '\n';
}
}
inf.close();
std::ifstream inf2{ "c:\\synergyii\\config\\newlines.txt" };
if (!inf2)
{
std::cerr << "Cannot open client config for reading" << std::endl;
return 1;
}
while (std::getline(inf2, strInput))
{
outf << strInput << '\n';
}
inf2.close();
outf << "</settings>" << '\n';
outf << "</config>" << '\n';
outf.close();
return 0;
}
Thanks,
V