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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:14:22+00:00 2026-06-04T13:14:22+00:00

I am trying to call a function based on user input. I cannt figure

  • 0

I am trying to call a function based on user input. I cannt figure out what I am doing wrong. I keep getting this error

error: no matching function for call to 'sort(std::vector<int, std::allocator<int> >&)'

Can someone tell me what I am doing wrong. Please explain any suggestions thoroughly as I am brand new to C++. Here is my code:

#include <iterator>
#include <algorithm>
#include <vector>
#include <fstream>
#include <iostream>
#include <string>

std::ifstream in("");
std::ofstream out("outputfile.txt");
std::vector<int> numbers;
std::string sortType = "";
std::string file = "";

int main()
{
  std::cout << "Which type of sort would you like to perform(sort or mergesort)?\n";
  std::cin >> sortType;

  std::cout << "Which file would you like to sort?\n";
  std::cin >> file;

  //Check if file exists
  if(!in)
  {
    std::cout << std::endl << "The File is corrupt or does not exist! ";
    return 1;
  }

  // Read all the ints from in:
  copy(std::istream_iterator<int>(in), std::istream_iterator<int>(),
            std::back_inserter(numbers));

  //check if the file has values
  if(numbers.empty())
  {
      std::cout << std::endl << "The file provided is empty!";
      return 1;
  } else
  {
      if(file == "sort")
      {
          sort(numbers);
      }else
      {
          mergeSort();
      }
  }
}

void sort(std::vector<int>)
{

  // Sort the vector:
  sort(numbers.begin(), numbers.end());

  unique(numbers.begin(), numbers.end());

  // Print the vector with tab separators:
  copy(numbers.begin(), numbers.end(),
            std::ostream_iterator<int>(std::cout, "\t"));
  std::cout << std::endl;

    // Write the vector to a text file
  copy(numbers.begin(), numbers.end(),
            std::ostream_iterator<int>(out, "\t"));
    std::cout << std::endl;
}

void mergeSort()
{
      //mergesort code..
}
  • 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-04T13:14:22+00:00Added an answer on June 4, 2026 at 1:14 pm

    You need to declare the sort function before you call it. Move its definition above main, or put void sort(std::vector<int>); before main.

    And the same goes for mergeSort.

    You should also fully qualify the call sort(numbers.begin(), numbers.end()); as std::sort(numbers.begin(), numbers.end());, and the same for copy, unique. If you don’t, then for technical reasons called “ADL”, which you can look up if you like, then the call only compiles if the arguments that you’re calling it on (the iterators) are classes in namespace std. It’s up to the specific implementation whether or not they are, so the call won’t work on some compilers.

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

Sidebar

Related Questions

I'm trying to call this function on my model User(I'm using mongoose). like this:
I'm trying to call a function that contains jQuery code. I want this function
I'm trying to call a function, and VS gives me an error (red underline),
I am trying to call terminate function. [I think this function gets called when
I'm trying to work out how the io_service.run() function operates in a client. This
I am trying out this example http://thinkdiff.net/facebook/new-javascript-sdk-oauth-2-0-based-fbconnect-tutorial/ But I am getting xml error which
I'm trying to call a function in a Python script from my main C++
I'm trying to call a function from a form within the same .php file,
I am trying to call a function makeQuery and it's not working, FireBug is
I am trying to call my function named isUrgencyTypeValid from my javascript code but

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.