如何让cout打印一定数量的字符?已经回答了

问题描述 投票:0回答:0

所以我必须编写一个代码来打印一行具有一定数量字符的文本。

std::ostream& Book::write(std::ostream& os) const {
    Publication::write(os);
    if (conIO(os)) {
        os << ' ';
        os.width(15); os << fixed << left << setfill(' ') << m_author << " |";
    }
    else {
        os << '\t' << m_author;
    }
    return os;
}

这是我的代码,但是当我运行程序时,它会打印完整的 m_author 而不是仅 15 个字符。如果 m_author 少于 15 个字符,则效果非常好。

我已经尝试过 Sterew() 并制作了一个 char 数组并且只打印 15 个字符,但它不起作用

c++ char cout
© www.soinside.com 2019 - 2024. All rights reserved.