标准C++库常见函数

1、 格式化输出:

1) width()函数:可以为接下来的所有显示要素指定默认的宽度。

2) setw()函数:设置数据项实用的宽度

3) fill()函数:当输入宽度非默认宽度时可以设置填充字符的值

4) setiosflags(ios::left)函数:表示输出值的对其方式

5) dec、hex和oct本别表示十进制、十六进制和八进制

6) put:把单个字符写入输入流中

7) get:类似于提取运算符>>,知识空字符被包含到输入中。

#include <iostream>
 
int main()
{
    char line[25], ch = 0, *cp;
 
    std::cout << " Type a line terminated by 'x'"
              << std::endl << '>';
    cp = line;
    while (ch != 'x')
    {
        std::cin >> ch;
        *cp++ = ch;
    }
    *cp = '/0';
    std::cout << ' ' << line;
 
    std::cout << "/n Type another one" << std::endl << '>';
    cp = line;
    ch = 0;
    while (ch != 'x')
    {
        std::cin.get(ch);
        *cp++ = ch;
    }
    *cp = '/0';
    std::cout << ' ' << line;
    
    return 0;
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2022-12-23
  • 2021-12-13
  • 2021-10-26
猜你喜欢
  • 2021-11-17
  • 2022-12-23
  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
  • 2022-02-17
  • 2022-01-17
相关资源
相似解决方案