说好今夜不点烟 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 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突