Hi Andy
Sorry for the vagueness. The program is long and has several parts to it. The text file being read is a list of settings we use when upgrading clients we sell. There are 2 files that get combined here. I'll post more of the code below. In the program the files are merged and then I am sorting it alphabetically. Later it gets added to an xml file which I have that part working out as need. However, we would put // comment lines above the settings. When I sort the final text it breaks the comments away from the settings. So that is why I am trying to move them to be behind the settings or whatever it is we add at that time. The two input files would look like this:
//This settings sets the background to black
<background>00</background>
//Allows users to colorize their buttons
<usercolorbuttons>true</usercolorbuttons>
//This is settings 3
<setting3>true</setting3>
etc...
I want it to look like this when it is done combining:
<background>00</background> //This settings sets the background to black
<usercolorbuttons>true</usercolorbuttons> //Allows users to colorize their buttons
<setting3>true</setting3> //This is settings 3
etc..
If it has to be done at a separate step that is fine. Just having trouble getting it going and I figured while I was reading it and checking for duplicates (that's the part that you are questioning I believe) that it could be done at the same time.
I don't have the sort line in there right now as it was not doing it the way I wanted because of how the 2 input files are laid out currently.
Let me know if that helps clarify.
Thanks,
V
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
vector<string> vlines31;
vector<string> vlines32;
set<string> slines31;
set<string> slines32;
for (string line31; getline(ifs31, line31); vlines31.push_back(line31))
if (line31.find("<settings>") != string::npos) {
vlines31.push_back(line31);
break;
}
for (const auto& v : vlines31)
ofs31 << v << '\n';
for (string line32; getline(ifs31, line32) && line32.find("<EndofFile>") == string::npos; ) {
line32.erase(remove_if(line32.begin(), line32.end(), isSpace), line32.end());
line32.erase(line32.find_last_not_of(" ") + 1);
const auto& result = slines32.insert(line32);
if (result.second)
vlines32.push_back(line32);
}
for (string line32; getline(in_newlines, line32);) {
line32.erase(remove_if(line32.begin(), line32.end(), isSpace), line32.end());
const auto& result = slines32.insert(line32);
if (result.second)
vlines32.push_back(line32);
}
for (auto it = vlines32.cbegin(); it != vlines32.cend(); ++it)
ofs31 << '\t' << '\t' << *it << '\n';
ifs31.close();
ofs31.close();
in_newlines.close();
|