?
Solved

doubt about sorting

Posted on 2004-03-26
3
Medium Priority
?
236 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
[X]
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
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 80 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.
Suggested Courses

752 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