Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

cout

endl

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;
}
like image 593
Jok3r Avatar asked Nov 29 '22 00:11

Jok3r


2 Answers

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

like image 165
4pie0 Avatar answered Dec 15 '22 15:12

4pie0


You forgot to add the proper library:

#include <iostream>
like image 37
user2076694 Avatar answered Dec 15 '22 15:12

user2076694