// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
#include <iostream>
#include <fstream>
#include <string>
#include <map>

const int CR = 1; // 1 with CR LF files (Windows), 0 with LF files (Unix)

using namespace std;

static ifstream f;
static map<string,streampos> lblpos;

void load()
{
   string line;
   while(!f.eof())
   {
       getline(f,line);
       if(line[0]==':')
       {
           lblpos.insert(make_pair(line.substr(1, line.length()-1-CR), f.tellg()));
       }
   }
   f.clear();
}

string find(string lbl)
{
    f.seekg(lblpos[lbl]);
    string line;
    getline(f,line);
    return line.substr(0, line.length()-CR);
}

int main()
{
   f.open("seek.txt", ios::binary);
   load();
   cout << find("b") << endl;
   cout << find("c") << endl;
   cout << find("a") << endl;
   f.close();
   return 0;
}
