写了一个类,在编译的时候出现了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";
}