C++ Sort Error "No instance of overloaded function.."

Episha

I'm still very new to C++ and programming in general, so I apologize if haven't the right information the first time

I started learning how to code with the book "Programming: Principles and Practice Using C++ (2nd Edition)" by Bjarne Stroustrup and I ran into some errors while using the code provided in chapter 4.6.4. Every time I go to run the code it tells me about "std::sort" and that there's no instance of overloaded function "std::sort" matches the argument list. There's also a new error in line 16 with i-1 as the IDE (Visual Studio 2013 Express) says the identifier is undefined.

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

int main()
{
std::vector<std::string>words;
for (std::string temp; std::cin >> temp;)
    words.push_back(temp);
std::cout << "Number of words: " << words.size() << std::endl;

std::sort(words);

for (int i = 0; i<words.size(); ++i)
    if (i == 0 || words[i–1] != words[i]) // is this a new word?
        std::cout << words[i] << "\n";
}

I can't seem to find out what's causing the error as I've put the required #include but it still shows the error. Any explanation would help tremendously.

Jamerson

std::sort takes a pair of iterators.

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

You could define your own helper function that takes one argument.

template<typename Container>
inline void sort(Container& c)
{
    std::sort(std::begin(c), std::end(c));
}

You probably want to create your own namespace for the helper function.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error: no instance of overloaded function "std::make_shared" matches the argument list

From Dev

Error : no instance of overloaded function

From Dev

Sort array error with Swift

From Dev

Collections.sort() error

From Dev

More than once instance of overloaded function when using default arguments in C++

From Dev

Error: More than one instance of overloaded function matches the argument list

From Dev

Merge sort algorithm error

From Dev

Count Sort in C - Error: Use of undeclared identifier

From Dev

c++ STL sort using my define function error

From Dev

std::bind() error: cannot determine which instance of overloaded function "boost::asio::io_service::run" is intended

From Dev

Error Implementing Derived Class Constructor: "No Instance of Overloaded Function Matches the Specified Type

From Dev

Vector of shared_ptr resulting in error: "no instance of overloaded function" when wanting to push_back vector list

From Dev

quick sort recursion error

From Dev

getSiblings() and sort_by error

From Dev

No instance of overloaded function when resizing

From Dev

More than one instance of overloaded function matches the argument list and I can't find where the error happens

From Dev

Merge Sort - Segmentation Error

From Dev

quick sort error in c++ using classes

From Dev

Insertion Sort Error C

From Dev

quick sort error using C++

From Dev

c++ struct in map as value - error "no instance of overloaded function matches the argument list"

From Dev

Selection Sort in C using an Array of Struct, error: "lvalue required..."

From Dev

Collections.sort() error

From Dev

C++ Sort Error "No instance of overloaded function.."

From Dev

sort:multi-character tab in C error

From Dev

Alternatives for 'egrep -o "success|error|fail" <filename> | sort | uniq -c'

From Dev

Vector of shared_ptr resulting in error: "no instance of overloaded function" when wanting to push_back vector list

From Dev

C++ Getline issues (No instance of overloaded function "getline"

From Dev

No instance of overloaded function for getline

Related Related

  1. 1

    Error: no instance of overloaded function "std::make_shared" matches the argument list

  2. 2

    Error : no instance of overloaded function

  3. 3

    Sort array error with Swift

  4. 4

    Collections.sort() error

  5. 5

    More than once instance of overloaded function when using default arguments in C++

  6. 6

    Error: More than one instance of overloaded function matches the argument list

  7. 7

    Merge sort algorithm error

  8. 8

    Count Sort in C - Error: Use of undeclared identifier

  9. 9

    c++ STL sort using my define function error

  10. 10

    std::bind() error: cannot determine which instance of overloaded function "boost::asio::io_service::run" is intended

  11. 11

    Error Implementing Derived Class Constructor: "No Instance of Overloaded Function Matches the Specified Type

  12. 12

    Vector of shared_ptr resulting in error: "no instance of overloaded function" when wanting to push_back vector list

  13. 13

    quick sort recursion error

  14. 14

    getSiblings() and sort_by error

  15. 15

    No instance of overloaded function when resizing

  16. 16

    More than one instance of overloaded function matches the argument list and I can't find where the error happens

  17. 17

    Merge Sort - Segmentation Error

  18. 18

    quick sort error in c++ using classes

  19. 19

    Insertion Sort Error C

  20. 20

    quick sort error using C++

  21. 21

    c++ struct in map as value - error "no instance of overloaded function matches the argument list"

  22. 22

    Selection Sort in C using an Array of Struct, error: "lvalue required..."

  23. 23

    Collections.sort() error

  24. 24

    C++ Sort Error "No instance of overloaded function.."

  25. 25

    sort:multi-character tab in C error

  26. 26

    Alternatives for 'egrep -o "success|error|fail" <filename> | sort | uniq -c'

  27. 27

    Vector of shared_ptr resulting in error: "no instance of overloaded function" when wanting to push_back vector list

  28. 28

    C++ Getline issues (No instance of overloaded function "getline"

  29. 29

    No instance of overloaded function for getline

HotTag

Archive