Basically I want to find the quickest way in which to search for data quickly, from a binary file.
For example my bin file will contain data such as:
0,Hello World,0
0,Another World,1
Now I would like to search for each new line of a 10,000 (possible more) .bin file. Currently I am doing it this way:
void FetchData(const unsigned int& line,int column, std::string& data)
{
if (file)
{
// reset file pointer to beginning
file.clear();
file.seekg(0, std::ios::beg);
if (fs.good())
{
// search for the desired line and exit loop
for (int i = 0; i < (line+1) && file.eof() == false; i++)
{
std::getline(file,data);
}
}
}
}
This does work, but are there any more efficient approaches I could take?
I am also required to modify such data, but I am currently storing the .bin file in a vector temporarily and the modify particular elements of the vector
and then overwrite the existing .bin file with the latest data. If there is a more efficient approach to this please let me know?
Also on a side note, how would performance differ between using an .xml instead of a .bin file ?
Thank you for any help offered.