不断收到"错误:使用未声明的标识符'cout'和错误:无法解析对重载函数的引用
Keep getting "error: use of undeclared identifier 'cout' and error: reference to overloaded function could not be resolved
我正在使用许多不同的函数编写一个排序程序,正如你们所看到的 我的声明。但是,当我尝试编译和运行我的程序时,我不断收到这些相同的错误 它们如下:
-
error: use of undeclared identifier 'cout'; did you mean 'count'?
cout << "Hello from main" << endl;
-
error: reference to overloaded function could not be resolved; did you mean to call it?
cout << "Hello from main" << endl;
-
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;
相关文章:
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- C++引用错误
- 已定义函数时出现 G++ "未定义的引用"错误
- 错误:使用通用引用的声明冲突
- 链接 cmake 时出现未定义的引用错误
- 错误:未定义对'oboe::AudioStreamBuilder::openStream(oboe::AudioStream**)'的引用
- 链接器错误:未定义对"Reference_Genome::seq[abi:cxx11]"的引用
- C++ 中的编译错误:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 错误:无法解析对重载函数的引用;你的意思是调用它吗?
- 在 gtest 中初始化堆栈上的引用变量的隔离错误
- 运行时错误:引用绑定到类型为"int"的空指针
- 隐式重新解释引用时强制转换,没有警告/错误
- 只有级联分类器会发出未定义的引用错误
- 错误:未定义对cv::cudacodec::createVideoReader的引用
- 模板流运算符重载错误:引用初始化无效,与basic_istream和basic_ifstream之间的差异有关
- 对于我的 ComplexNumber 中的某些方法,我得到了一个奇怪的未定义错误引用.cpp,不过我对模板很陌生
- 从对象调用成员对象,错误:引用非常量值的初始值必须是左值
- Qt并发错误:引用非静态成员