Keep getting "error: use of undeclared identifier 'cout' and error: reference to overloaded function could not be resolved

16,890

Solution 1

You have to #include <iostream>. It is where std::cout is declared.

Solution 2

You forgot to add the proper library:

#include <iostream>

Solution 3

You should add #include <iostream> in the beginning of your program

Solution 4

Check for these lines in the beginning of your c++ program.

#include <iostream>
using namespace std;

Share:
16,890
Jok3r
Author by

Jok3r

Updated on June 14, 2022

Comments

  • Jok3r
    Jok3r almost 2 years

    I am writing a sorting program using a host of different functions as y'all can see from my declarations. However, I keep getting these same errors when I try to compile and run my program they are as follows:

    1. error: use of undeclared identifier 'cout'; did you mean 'count'?

      cout << "Hello from main" << endl;

    2. error: reference to overloaded function could not be resolved; did you mean to call it?

      cout << "Hello from main" << endl;

    3. error: use of undeclared identifier 'endl'; did you mean 'end'? cout << "Hello from main" << endl;

    I'm not really sure why I am getting these errors....I thought I included everything I needed to in order to use "cout" and "endl" when I included using namespace std... I have a feeling it has something to do with all my function declarations, but that's just a hunch Any help that y'all can give would be greatly appreciated!!!!!

    #include <vector>
    #include <functional>
    #include <algorithm>
    using namespace std;
    
    template <typename Comparable>
    void insertionSort(vector<Comparable> & a);
    
    template <typename Comparable>
    void heapsort(vector<Comparable> & a);
    
    template <typename Comparable>
    void percDown(vector<Comparable> & a, int i, int n);
    
    template <typename Comparable>
    void mergeSort(vector<Comparable> & a, vector<Comparable> & tmpArray, int left, int right);
    
    template <typename Comparable>
    void mergeSort(vector<Comparable> & a);
    
    template <typename Comparable>
    void merge(vector<Comparable> & a, vector<Comparable> & tmpArray, int leftPos, int rightPos, int rightEnd);
    
    template <typename Comparable>
    void quicksort(vector<Comparable> & a);
    
    template <typename Comparable>
    const Comparable & median3(vector<Comparable> & a, int left, int right);
    
    template <typename Comparable>
    void quicksort(vector<Comparable> & a, int left, int right);
    
    
    int main()
    {
        vector<int> myVector;
        cout << "Hello from main" << endl; ///This is where the error is//////
        return 0;
    }