说好今夜不点烟 2017-01-30 09:39 采纳率: 100%
浏览 1121
已采纳

帮忙解答下谢谢谢谢谢谢谢谢谢


#ifndef CP5_ex7_24_h
#define CP5_ex7_24_h

#include <string>

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

    Screen() = default; // 1
    Screen(pos ht, pos wd) : height(ht), width(wd), contents(ht * wd, ' ') {} // 2
    Screen(pos ht, pos wd, char c) : height(ht), width(wd), contents(ht * wd, c)
    {
    } // 3

    char get() const { return contents[cursor]; }
    char get(pos r, pos c) const { return contents[r * width + c]; }

private:
    pos cursor = 0;
    pos height = 0, width = 0;
    std::string contents;
};

#endif

其中contents(ht * wd, c)这个什么意思 contents不是string类型的吗?(ht * wd, c)是什么意思呢

  • 写回答

1条回答 默认 最新

  • Xefvan 2017-01-30 11:51
    关注

    这是string构造函数的一个重载

    basic_string( size_type count,
    CharT ch,
    const Allocator& alloc = Allocator() );

    相当于contents由ht*wd个c组成

    随便拿一个代码试一下就知道了

    #include <iostream>
    #include <string>
    using namespace std;
    
    int main(int argc, char const *argv[])
    {
        string s(10, 'c');
        cout << s << endl;      // s=cccccccccc
        return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘