标题:未定义的标识符,明明定义了啊。。
只看楼主
哒哒哒啦啦啦
Rank: 1
等 级:新手上路
帖 子:75
专家分:4
注 册:2016-2-26
结帖率:76.92%
已结贴  问题点数:30 回复次数:3 
未定义的标识符,明明定义了啊。。

头文件
*****************************************************************8
#ifndef TOUTOU_H
#define TOUTOU_H

#include<iostream>
#include<string>
using namespace std;
using std::iostream;
using std::string;
using std::cout;
class Screen {
public:
    using pos = std::string::size_type;

    Screen() = default;
    Screen(pos ht, pos wd) :height(ht), width(wd), conents(ht*wd, ' ') {}
    Screen(pos ht, pos wd, char c) :height(ht), width(wd), conents(ht*wd, c) {}

    char get() const { return conents[cursor]; }                                         ***********   cursor未定义
    char get(pos r, pos s)  const { return conents[r*width + s]; }
    Screen &move(pos r, pos s);
    Screen &set(char c);
    Screen &set(pos r, pos s, char c);

    const Screen &display(std::ostream &os) const { do_display(os); return *this; }
    Screen &display(std::ostream &os) { do_display(os); return *this; }

private:
    void do_display const (ostream &os) {
        os << conents;
    }
private:
    pos cursor = 0;
    pos height = 0;
    std::string conents;
    pos width = 0;
};
inline Screen& Screen::move(pos r, pos s) {
    cursor = r*width + s;
    return *this;
}

inline Screen& Screen::set(char c) {
    conents[cursor] = c;
    return *this;
}

inline Screen& Screen::set(pos r, pos s, char c) {
    conents[r*width + s] = c;
    return *this;
}
#endif
 
程序
**********************************************************************
#include"C:\Users\Jin\Desktop\toutou.h"
int main()
{
   

   
    Screen myScreen(5,5,'X');                            ******************* Screen未定义
    myScreen.move(4, 0).set('#').display(cout);          ******************* cout未定义
     cout << "\n";
    myScreen.display(cout);
    cout << "\n";

    return 0;
}
搜索更多相关主题的帖子: default include public 
2016-05-16 22:32
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:11 
代码抄的吧,而且还是抄了一个对C++狗屁不通的人的代码。各种C++规范不遵守,风格和用法不遵守

程序代码:
#include <iostream>
#include <string>

class Screen
{
public:
    using pos = std::string::size_type;

    Screen() = default;
    Screen( pos height, pos width, char c ) :height_(height), width_(width), content_(height_*width_,c)
    {
    }

    Screen& move( pos r, pos s )
    {
        cursor_ = r*width_ + s;
        return *this;
    }

    char at() const
    {
        return content_[cursor_];
    }
    char& at()
    {
        return content_[cursor_];
    }

    char at( pos r, pos c )  const
    {
        return content_[r*width_+c];
    }
    char& at( pos r, pos c )
    {
        return content_[r*width_+c];
    }

private:
    pos height_ = 0;
    pos width_ = 0;
    std::string content_;
    pos cursor_ = 0;

    friend std::ostream& operator<<( std::ostream& os, const Screen& scr );
};

std::ostream& operator<<( std::ostream& os, const Screen& scr )
{
    for( auto r=0; r!=scr.height_; ++r )
    {
        os.write( scr.content_.c_str()+r*scr.width_, scr.width_ );
        os.write( "\n", 1 );
    }
    return os;
}

using namespace std;

int main( void )
{
    Screen scr( 5, 5, 'X' );
    cout << scr << '\n';

    scr.move(4,0).at() = '#';
    cout << scr << '\n';

    scr.at(4,4) = '#';
    cout << scr << '\n';

    return 0;
}

输出
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX

XXXXX
XXXXX
XXXXX
XXXXX
#XXXX

XXXXX
XXXXX
XXXXX
XXXXX
#XXX#

2016-05-17 08:47
哒哒哒啦啦啦
Rank: 1
等 级:新手上路
帖 子:75
专家分:4
注 册:2016-2-26
得分:0 
回复 2楼 rjsp
是一个题在github上的答案,不知原来的代码为啥不对呢
2016-05-17 20:36
QQ328626969
Rank: 2
等 级:论坛游民
帖 子:8
专家分:11
注 册:2016-4-26
得分:11 
2016-05-18 22:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-464900-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.250283 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved