[英]Cout and endl errors
I have listed my code below. 我在下面列出了我的代码。 I get soooo many errors saying cout and endl was not declared in this scope.
我得到了很多错误,说cout和endl没有在这个范围内声明。 I do not know what I am doing wrong or how to force the class to recognise cout?
我不知道我做错了什么或如何强迫班级认出cout? I hope I am explaining my problem correctly.
我希望我正确地解释我的问题。 If I comment out the methods (not the constructor) it works.
如果我注释掉方法(不是构造函数),它就可以工作。 I am probably just making a novice mistake here - please help.
我可能只是在这里犯了一个新手错误 - 请帮助。
using namespace std;
class SignatureDemo{
public:
SignatureDemo (int val):m_Val(val){}
void demo(int n){
cout<<++m_Val<<"\tdemo(int)"<<endl;
}
void demo(int n)const{
cout<<m_Val<<"\tdemo(int) const"<<endl;
}
void demo(short s){
cout<<++m_Val<<"\tdemo(short)"<<endl;
}
void demo(float f){
cout<<++m_Val<<"\tdemo(float)"<<endl;
}
void demo(float f) const{
cout<<m_Val<<"\tdemo(float) const"<<endl;
}
void demo(double d){
cout<<++m_Val<<"\tdemo(double)"<<endl;
}
private:
int m_Val;
};
int main()
{
SignatureDemo sd(5);
return 0;
}
The compiler needs to know where to find std::cout
first. 编译器需要首先知道在哪里找到
std::cout
。 You just need to include the correct header file: 您只需要包含正确的头文件:
#include <iostream>
I'd suggest you not to pollute the namespace using using
directives. 我建议你不要使用
using
指令污染命名空间。 Instead either learn to prefix std classes/objects with std::
or use specific using
directives: 相反,要么学会使用
std::
为std类/对象加前缀,要么使用特定的using
指令:
using std::cout;
using std::endl;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.