不断收到"错误:使用未声明的标识符'cout'和错误:无法解析对重载函数的引用

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

本文关键字:错误 引用 函数 重载 cout 未声明 标识符      更新时间:2023-10-16

我正在使用许多不同的函数编写一个排序程序,正如你们所看到的 我的声明。但是,当我尝试编译和运行我的程序时,我不断收到这些相同的错误 它们如下:

  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;

真的不确定为什么我会收到这些错误....我以为我包含了我需要的一切为了在我包含使用命名空间 std 时使用"cout"和"endl"......我有一种感觉,它与我所有的函数声明有关,但这只是一种预感你们能提供的任何帮助将不胜感激!!!!

#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;
}

你必须#include <iostream> .这是宣布std::cout的地方。

您忘记添加正确的库:

#include <iostream>

你应该在程序的开头添加#include <iostream>

在 c++ 程序的开头检查这些行。

#include <iostream>
using namespace std;