Hey,
I have a file of RGB values, seperated by : just so they count as a single line.
I'm importing these into a string vector and sorting these so they come out sorted from 0:0:0 to 99:99:99.
vector<string> sV;
ifstream in("Images\\Stage1RBGList.txt", std::ios::binary);
string word;
cout << "Starting Compression..." << endl;
while(in >> word)
sV.push_back(word);
sort( sV.begin(), sV.end() );
ofstream myfile2;
myfile2.open ("Images\\Stage2SortedRBGList.txt", std::ios::binary);
cout << "Starting Sorting..." << endl;
for(int i = 0; i < sV.size(); i++)
myfile2 << sV[i] << endl;
myfile2.close();
cout << "Sorting Ended" << endl;
This works fine.
Next I'm trying to count the duplicates in the file, such that I can replace them with a small symbol to reduce size.
e.g.
0:0:0
0:0:0
0:0:0
0:0:0
0:0:0
0:0:0
0:0:0
0:0:10
0:0:12
0:0:16
goes to:
a=0:0:0
7a
0:0:10
0:0:12
0:0:16
I'm sure I'm just being retarded on this point, but my code never seems to count them properly, or go past the first counter.
string uniqueString[10];
int counter[10];
ifstream inTxtFile("Images\\Stage2SortedRBGList.txt", std::ios::binary);
string lineRead;
bool found = false;
inTxtFile >> lineRead;
uniqueString[0] = lineRead;
counter[0] = 1;
cout << uniqueString[0] << endl;
while(inTxtFile >> lineRead)
{
for(int arraycell = 0; arraycell < 10; arraycell++)
{
found = false;
if (uniqueString[arraycell] == lineRead)
{
if (found == true)
{
break;
}
else
{
//cout << "Match Found @ " << arraycell << " " << lineRead << endl;
counter[arraycell] = counter[arraycell] + 1;
found = true;
break;
}
}
}
}
This should:
1) Populate the first uniqueString[] with the first symbol
2) for every line in the file
3) Scan uniqueString[]
4) If match found, increase counter array by 1
5) If not found by end of the uniqueString[] , add to last spot
6) Once whole uniqueString[] full up, assign symbols and replace those lines in File1.
From what I've debugged, It adds the first symbol 0:0:0 to uniqueString[0].
And scans through rest, Breaking out if same 0:0:0, but counter doesn't increase, and after it passes 0:0:0 it doesn't add the next string 0:0:10.
I'm sure I'm just being stupid here, But anything I'm blatantly missing? I know point 6 won't work, as that's not implemented yet.
Thanks Lilly