Solved

doubt about sorting

Posted on 2004-03-26
3
233 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

730 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