Solved

doubt about sorting

Posted on 2004-03-26
3
229 Views
Last Modified: 2010-04-01
I have input file with following contents

abc,1111ab@1111bb@1111aa
xyz,2222dd@2222dc@2222da@2222tt

first field is city & second is list of pocos.In first line there r 3 pocos & in second line 4 pocos there can be n no.of pocos.I want to sort the pocos.How to it in c++?


Can anyone help me?
0
Comment
Question by:girija_cv
3 Comments
 
LVL 12

Expert Comment

by:stefan73
ID: 10685259
Hi girija_cv,
Please clarify which sort order you want. All pocos (?) together, by city as primary sort key, or what?

Cheers,

Stefan
0
 

Author Comment

by:girija_cv
ID: 10685447
only poco sort
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 20 total points
ID: 10685534
     string line = "abc,1111ff@1111xx@1111ss@1111as";
      string city;
      list<string> poco_list;
      istringstream ssLine (line);
        getline(ssLine, city, ',');
      while (!ssLine.eof())
      {
          string poco;
            getline(ssLine, poco, '@');
          if (poco.empty())
              break;
          poco_list.push_back(poco);
      }
      poco_list.sort();
      for (list<string>::iterator it = poco_list.begin(); it != poco_list.end(); ++it)
          cout << *it << '@';
      cout << endl << endl;

Hope, that helps
Alex
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now