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 6382059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:28:26+00:00 2026-05-25T02:28:26+00:00

#include <algorithm> #include <iostream> #include <iterator> #include <string> #include <vector> #include <utility> using namespace

  • 0
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include <utility>

using namespace std;

typedef pair<int,int> Pair;

inline bool less_than_second( const Pair& b1, const Pair& b2 ){
   return b1.second < b2.second;
}

int main()
{
   const int SP1[] = { 2,53,21,55,36,5,1};
   const int EP1[] = { 18, 20, 26, 30, 41,1,5 };
         int i;


   const int num_pairs = sizeof( SP1 ) / sizeof( SP1[0] );
    vector<int> sm(num_pairs);

      // vector <int> SP;

   vector<Pair> pair( num_pairs );
   transform( EP1, EP1+num_pairs, SP1,pair.begin(), make_pair<int,int> );// MAKE PAIR

   sort( pair.begin(), pair.end() );

   sort( pair.begin(), pair.end(), less_than_second );

   vector<Pair>::const_iterator pair_end = pair.end();
    vector<int> SP,EP;
    vector<int>::iterator low,up;

   for( vector<Pair>::const_iterator ptr = pair.begin();ptr != pair_end; ++ptr )
   {

            int SP = ptr->second;
        int EP = ptr->first;

      cout<<"("<<SP<<","<<EP<<")\n";
      } 
   //cout<<"("<<SP<<","<<EP<<")\n";
   low=lower_bound (SP.begin(), SP.end(), 20); 
   up= upper_bound (SP.begin(), SP.end(), 20);

  cout << "lower_bound at position " << int(low- SP.begin()) << endl;
  cout << "upper_bound at position " << int(up - SP.begin()) << endl;


   up= upper_bound (pair.begin(), pair.end(), 20);                


  cout << "upper_bound at position " << int(up - pair.begin()) << endl;

   getchar();
}

I Sorted the pair vector and I am trying to get the values of upper_bound of one the vector in the pair, but it gives me
upper_bound at position = 0.

Please bear with me, I am a newbie to c++ and want to learn. Please help to fix this code. Thank you

  • 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-25T02:28:26+00:00Added an answer on May 25, 2026 at 2:28 am

    As far as I can tell, you never put any data into the SP vector. It’s possible that instead of int SP = ptr->second; you meant SP.push_back(ptr->second);.

    As a side note, since sort isn’t stable there’s no point in calling sort( pair.begin(), pair.end() ); before you sort it with your predicate.

    Finally, you may wish to pick up one of the books in The Definitive C++ Book Guide and List to help you learn the language.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main(void) {
I have following code #include <iostream> #include <string> #include <algorithm> using namespace std; int
#include <boost/algorithm/string.hpp> #include <vector> #include <iostream> #include <string> using namespace std; using namespace boost;
#include <iostream> #include <vector> #include <iterator> using namespace std; struct Point { int x;
Here's the code: #include <iostream> #include <string> #include <algorithm> using namespace std; int main()
#include <iostream> #include <vector> #include <algorithm> #include <iterator> #include <functional> #include <deque> using namespace
Given the code: #include <iostream> #include <cctype> #include <string> #include <algorithm> using namespace std;
#include <list> #include <set> #include <iterator> #include <algorithm> using namespace std; class MyContainer {
#include <iostream> using namespace std; int main() { double u = 0; double w
#include<iostream> using namespace std; class A { int a; int b; public: void eat()

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.