Posted on 2004-04-17
Last Modified: 2010-04-01
I have 2 input files xx.txt & yy.txt

contents of xx.txt are as follows
fields are city,cu,x,y,poco

contents of yy.txt are as follows

4555 xx,girija

fields are poco & city.

I want to match 4 digit poco & city of yy.txt  with poco & city of xx.txt.if they are matched 7digit poco of yy.txt should be appennded.output should be as follows.

Aardenburg,,34394,512775,4527,@4527 AA@4527 AB
Aardenburg,,30000,500000,4527,@4527 AA@4527 AB

the coding is as follows

#include <map>
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <conio.h>
#include <list>
using namespace std;
typedef multimap<string,string> yy;
void process_yy(yy &);
void process_xx(yy &);

string toUpper(string strText)
      transform(strText.begin(), strText.end(), strText.begin(), toupper);
      return strText;

int main( )
      yy YY;


void process_xx(yy &YY)
      list<string> list1;
      ifstream f_road("xx.txt");
      string line_str,str_element,ct,p;
      string city,poco,cu,x,y,add;
      string xx_cu_key,xx_key;
      int i,j;
      typedef pair <string, string> Int_Pair;
      multimap<string,string>::iterator it;
      multimap<string,string>::iterator it1;
      multimap<string,string>::iterator last_el;
      multimap<string,string>::iterator last_el1;

ofstream f_match("match.txt");
            ofstream f_nomatch("nomatch.txt");
            std::istringstream istr(line_str);
            string city_org,cu_org;

            city = toUpper(city_org);



                        add = it->second;
                        std::istringstream istr1(add);
                        cout<<city<<','<<cu<<','<<x<<','<<y<<','<<poco<<','<<it->second<<',' ;
                        copy (list1.begin(),list1.end(),std::ostream_iterator<std::string>(f_match));


void process_yy(yy  & YY)
      ifstream f_road("yy.txt");
      string line_str,str_element;
      string city,poco_n,poco,yy_key;
      typedef pair <string, string> Int_Pair;

            std::istringstream istr(line_str);
            poco= poco_n.substr(0,4);
            city = city + ',' + poco_n;
      multimap<string,string>::iterator it;


but it prints the o/p as follows.

Aardenburg,,34394,512775,4527,@4527 AA@4527 AB

can anyone giude me?

Question by:girija_cv
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Expert Comment

ID: 10848705
20 points is not going to get you far ...
I understand that your problem is that the multimap is not containing all records, so check the place where you insert these records and print a trace just before the insert and afterwards check if it was inserted.

I suggest that first you use C++ as you should and encapsulate reading from each file.
Then apply the processes to the adecuate object.
It will be much easier to debug and maintain.
LVL 39

Accepted Solution

itsmeandnobodyelse earned 20 total points
ID: 10848758
I wonder that  you got any output with that code. First it doesn't compile because there was a bracket error, and second it doesn't match any key.
The reason for this is easy:

In your first file poco is only a number, e.g. 4527, in your second file it is a string, say "4527 AA". When setting the key to the map as number and searching using the string it couldn't work. To solve this, simply strip the AA, AB extension before appending poco to the city string:

         string poco_n = poco.substr(0, 4);

         it = YY.find(city);

Regards, Alex

LVL 39

Expert Comment

ID: 10848813
>> 20 points is not going to get you far ...

I learned from one of your previous questions that could not give more points as you have no more left. I suppose, you know that you could get more points if you spend some money to EE.. Also, you already spend a lot of points not getting a final solution to your task. The reason for this is your input files that always are changing from question to question and most of your problems you only got because your code doesn't reflect these changes. If you had given us a good spec, two input file definitions that would hold longer than a day and say 300 points some weeks before, you would have now a better solution and still points left.

Regards, Alex

BTW, if you would post here a final spec, i would show you a much better coding than that you have til now. And i don't need more points... ;-)


Expert Comment

ID: 11078596
Give the points to  itsmeandnobodyelse

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

634 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question