reference file or reference value

Hi experts,
my input file is like this:

A         B
1         2
AA      BB

my refernece file is like this:

A      B       C
1      2       3
AA    BB     CC

I want to return
on my output file

I am going to do


1-2 3
in my reference file and my input file and compare them, if match then return value

So, I have the followings
typedef struct
       char keydata[100];
       char valuedata[100];

char* findkeyvalue( keyref* ref, const char* k)
         for(int i=0;i <MaxSize;i++)
              if (!strcmp(ref[i].keydata, k))
                     return ref[i].valuedata;
          return "NONE"

     ifstream fin( myinputfile);
     ifstream fin1( myreferencefile);
     keyfer refer_data[MaxSize];
     string refer_read;
     int k=0;
     getline(fin1, refer_read)
     while( getline (fin1, refer_read))
          vector<string> refer_row_elem;
          Getfields(refer_read1, refer1_row_elem, ',');
          refer_row_elem[0] += "-";
          refer_row_elem[0] += refer_row_elem[1];
          strcpy(refe_data[k].keydata, refer_row_elem[0].c_str());
          strcpy(refe_data[k].valuedata, refer_row_elem[2].c_str());

       while( getline (fin, row_read))
          vector<string> row_elem;
          Getfields(row_read, row_elem, ',');
          row_elem[0] += "-";
          row_elem[0] += row_elem[1];

       char * valuefound;
       valuefound = findkeyvalue(refer_data, row_elem[0].c_str());  
It returns NONE, no match found, Whats wrong ?
If I compare just 2 columns, no +=, then  I have match.
But after +=, then no match found.

Thanks in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can do this with a map, which has a pair of strings as its key. Here's how:
#include <iostream>
#include <fstream>
#include <sstream>
#include <map>

int main()
      typedef std::pair<std::string,std::string> Key;
      typedef std::map<Key,std::string> Map;

      std::string line;
      Map map;

      // Load the map using the reference file
            std::ifstream fref("ref.dat");
            while (getline(fref,line)) {
                  std::istringstream is(line);
                  std::string value;
                  Key key;
                  if (is >> key.first >> key.second >> value)
                        map[key] = value;

      // Load the map using the reference file
            std::ifstream fkey("key.dat");
            std::ofstream fout("out.dat");
            while (getline(fkey,line)) {
                  std::istringstream is(line);
                  Key key;
                  if (is >> key.first >> key.second)
                        fout << map[key] << '\n';

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Second comment should read:

// Load the map using the key file and generate the output file
I'll try that again... Second comment should read:

/* Read through key file and generate the output file doing look-ups on the map (assumes all keys have values in the reference file missing values will show as blank lines) */
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.