Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4559536
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:48:09+00:00 2026-05-21T17:48:09+00:00

I was trying to sort a vector of struct.The following is my code.I am

  • 0

I was trying to sort a vector of struct.The following is my code.I am not able to sort it properly…Can anyone help me..?I need to sort according to the mmNo.Sorry …i missed some part of the code…

typedef struct MMInfo
{
  std :: string strMmNo;
  std :: string strMmName;
  std :: string strMmsPlace;
  std :: string strMmAdd;
  std :: string strMmPh;

  MMInfo(const std::string& mmNo,
         const std::string& mmName,
         const std::string& mmPlace,
         const std::string& mmAdd,
         const std::string& mmPh) : stringValue(mmNo,),stringValue(mmName),
                                    stringValue(mmPlace),stringValue(mmAdd),
                                    stringValue(mmPh) {}

  bool operator < (const MMInfo& str) const
  {
    return (mmNo < str.mmNo);
  }

} MMInfo;

std::vector < MMInfo > mmlist;
MMInfo mmInfo = {"", "", "", "", ""};

mmInfo.strMmNo = "3452132";   //actually , i have used a loop to get it from the user
mmInfo.strMmName="Peter";
mmInfo.strMmPlace="TCR";
mmInfo.strMmAdd="Street 453";
mmInfo.strMmPh="8587556587";

mmlist.push_back(mmInfo);

sort(mmlist.begin(),mmlist.end());
for (int i=0; i<mmlist.size(); i++)
{
  cout << " first row :" << mmlist[i].strMmNo << " " << mmlist[i].strMmName 
       <<" " <<mmlist[i].strMmsPlace  << " " << mmlist[i].strMmsAdd ;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T17:48:10+00:00Added an answer on May 21, 2026 at 5:48 pm

    Your code has no problems. I mean, the usage is right but the structure definition seems not correct. It’s not compilable at least in Visual C++ 9.0 Please make a proper initialization list. The following code worked fine for me

    #include <iostream>
    #include <string>
    #include <vector>
    #include <algorithm>
    
    using namespace std;
    
    typedef struct NodeInfo
    {
        int x;
    
        NodeInfo( int xi ){ x = xi;  }
        bool operator < (const NodeInfo& str) const
        {
            return (x < str.x);
        }
    }MMInfo;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        std::vector < MMInfo > mmlist;
    
        mmlist.push_back( 1 );
        mmlist.push_back( 31 );
        mmlist.push_back( 21 );
        mmlist.push_back( 11 );
        mmlist.push_back( 41 );
        sort(mmlist.begin(),mmlist.end());
        for (unsigned int i=0; i<mmlist.size(); i++)
        {
            cout<< " x row : \n" << mmlist[i].x ;
        }
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to sort vector of struct's elements,but i can't construct vector itself
I'm trying to sort a Vector in java but my Vector is not a
I am trying to sort a vector of custom struct in C++ struct Book{
Trying to sort this array of objects according to (1) depth and (2) weight,
I am trying to sort but there is a nil. How can i get
I'm trying to sort a multidimensional array in objective-c i know that i can
I'm trying to compile this code with GCC 4.5.0: #include <algorithm> #include <vector> template
Within a class, I am trying to sort a vector, by passing a method
I'm trying to sort a vector of objects using a predicate function and I'm
I am trying to sort a vector below using boost::phoenix library. The class Foo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.