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

  • Home
  • SEARCH
  • 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 7951331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:31:43+00:00 2026-06-04T02:31:43+00:00

Possible Duplicate: Sort list using stl sort function My question is can we sort

  • 0

Possible Duplicate:
Sort list using stl sort function

My question is can we sort two std::lists using std::sort function? I have 2 string lists

  std::list<std::string>list1, list2;
  .....//entering values to list
  std::sort(list1.begin(), list1.end());

  std::sort(list2.begin(), list2.end());

while i am sorting these lists i am getting error.
I tried with std::vector, at this time the sort works.

The error is like

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility(1158) :
see declaration of ‘std::operator -‘
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\algorithm(3642):
error C2784: ‘_Base1::difference_type std::operator –
(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)’ :
could not deduce template argument for ‘const std::_Revranit<_RanIt,_Base> &’
from ‘std::_List_iterator<_Mylist>’
1> with
1> [
1> _Mylist=std::_List_valstd::string,std::allocator<std::string>
1> ]

I have to know that only std::sort supports lists?

  • 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-06-04T02:31:45+00:00Added an answer on June 4, 2026 at 2:31 am

    You can’t use std::sort to sort std::list, because std::sort requires iterators to be random access, and std::list iterators are only bidirectional.

    However, std::list has a member function sort that will sort it:

    list.sort();
    // if you want to use a comparator different from the default one:
    // list.sort(comparator);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Sort list using stl sort function The C++ standard library gives strict
Possible Duplicate: Python analog of natsort function (sort a list using a “natural order”
Possible Duplicate: Which sorting algorithm is used by STL’s list::sort()? Which sorting algorithm can
Possible Duplicate: Is std::list<>::sort stable? Does C++ std::list sort function is guaranteed to preserve
Possible Duplicate: Natural Sort Order in C# I have a list with a lot
Possible Duplicate: Does std::list::remove method call destructor of each removed element? I have a
Possible Duplicate: Easiest way to sort DOM nodes? I have a list of DIVs,
Possible Duplicate: Sort a Custom Class List<> I have a Generic Collector List and
Possible Duplicate: How may I sort a list alphabetically using jQuery? Technology: Asp.net with
Possible Duplicate: how to sort by length of string followed by alphabetical order? I

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.