[英]Does anyone know the difference between endl(cout) and cout << endl?
[英]Cout and endl errors
我在下面列出了我的代碼。 我得到了很多錯誤,說cout和endl沒有在這個范圍內聲明。 我不知道我做錯了什么或如何強迫班級認出cout? 我希望我正確地解釋我的問題。 如果我注釋掉方法(不是構造函數),它就可以工作。 我可能只是在這里犯了一個新手錯誤 - 請幫助。
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;
}
編譯器需要首先知道在哪里找到std::cout
。 您只需要包含正確的頭文件:
#include <iostream>
我建議你不要使用using
指令污染命名空間。 相反,要么學會使用std::
為std類/對象加前綴,要么使用特定的using
指令:
using std::cout;
using std::endl;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.