首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cout和endl错误

Cout和endl错误
EN

Stack Overflow用户
提问于 2013-10-12 15:12:21
回答 1查看 20K关注 0票数 6

我已经在下面列出了我的代码。我收到了很多错误,说cout和endl没有在这个作用域中声明。我不知道我做错了什么,也不知道如何迫使类识别cout?我希望我正确地解释了我的问题。如果我注释掉方法(而不是构造器),它就能工作。我可能只是犯了一个新手的错误--请帮帮忙。

代码语言:javascript
复制
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;
}
EN

回答 1

Stack Overflow用户

发布于 2013-10-12 22:02:00

编译器首先需要知道在哪里可以找到std::cout。您只需要包含正确的头文件:

代码语言:javascript
复制
#include <iostream>

我建议您不要使用using指令污染名称空间。相反,要么学习使用std::作为标准类/对象的前缀,要么使用特定的using指令:

代码语言:javascript
复制
using std::cout;
using std::endl;
票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19331575

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档