Patrick_Adair
Patrick_Adair
采纳率100%
2016-08-02 02:15 阅读 3.8k
已采纳

编译出现error C2065: “cout”: 未声明的标识符错误

20

写了一个类,在编译的时候出现了error C2065: “cout”: 未声明的标识符错误,请问如何修改程序?
class Screen
{
private:
unsigned height = 0, width = 0;
unsigned cursor = 0;
std::string contents;
public:
Screen() = default;
Screen(unsigned ht,unsigned wd):height(ht),width(wd),contents(ht*wd,' '){ }
Screen(unsigned ht,unsigned wd,char c):height(ht),width(wd),contents(ht*wd,c){ }
public:
Screen& move(unsigned r, unsigned c)
{
cursor = r*width + c;
return *this;
}
Screen& set(char ch)
{
contents[cursor] = ch;
return *this;
}
Screen& set(unsigned r, unsigned c, char ch)
{
contents[r*width + c] = ch;
return *this;
}
Screen& display()
{
cout << contents;
return *this;
}
};
源文件为:
#include
#include "Sales_data.h"
using namespace std;

int main()
{
Screen myScreen(5, 5, 'X');
myScreen.move(4, 0).set('#').display();
cout << "\n";
myScreen.display();
cout << "\n";
}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • 已采纳
    feng1790291543 鱼弦 2016-08-02 02:18

    加头文件: #include
    using namespace std:

    cout 使用一般都是 std::cout<<XXXX

    点赞 1 评论 复制链接分享
  • qq_31655965 Sharember 2016-08-02 03:12

    #include
    using namespace std;
    void main(){
    cout<<"hello world";
    ]

    点赞 评论 复制链接分享
  • Runner__1 T_world 2016-08-04 09:13
    #include <iostream>
    using namespace std;
    
    
    点赞 评论 复制链接分享

相关推荐