Solved

doubt about sorting

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MSVCR80.dll crash 2 138
Handle Exceptions during instantiation 28 414
Unresolved External Symbols 3 80
Better understanding on C++ Class serialization and formats 9 65
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…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

813 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

9 Experts available now in Live!

Get 1:1 Help Now