Instead of storing the entire line as a string, why not map the two values to key/value entries into a std::map ? Something along the lines of
while (file1.good ()) {
file1 >> ids;
file1.getline (val, VAL_SIZE);
lut[key] = val;
}
// Then to look up a certain key...
if (lut.find (ids_key) != lut.end ()) {
// you have a matching key...
}
L7Sqr
Practically a Master Poster
657 posts since Feb 2011
Reputation Points: 201
Solved Threads: 124
so can only search for the IDS_STRING part. How can I achieve that?
try a little somethin' like this:
vector<string> text_file;
//load the vector........
//find substrings in your vector:
for(int i=0, size=text_file.size(); i<size; i++)
{
if(text_file[i].substr("IDS_STRING") != string::npos)
{
//found
}
else
{
//not found
}
}
I'm basically trying to go through the file and see if each IDS_STRING number exists, so from 1 to 4000, and if it doesn't I want to write a new line in the file with the IDS_STRING number.
This isn't too terribly difficult; however, the data structure ye' have chosen (vector) is a poor container when it comes to insertion that does not occur at the very end. A better choice for your application would be the class... which is very similar to but offers an efficient insert() function ( offers the efficiency of a double-linked list data structure, unlike the array type of ) So, what you would want to do is to populate your list and sort it using the sort() function from . You would want to (and have to) use the overloaded version of sort() that allows you to pass in your own custom compare function. This will allow you the flexibility to parse the list elements and perform a strict < less than comparison between elements. Sort the list, perform insertions as desired, open a file to write to. (if file already exists, open using the ios::trunc flag to overwrite the file)
Clinton Portis
Practically a Posting Shark
833 posts since Oct 2005
Reputation Points: 237
Solved Threads: 118