您现在的位置是:首页 > 编程 > 

setw()函数使用,#include <iomanip> ——using std::setw;

2025-07-29 01:12:02
setw()函数使用,#include <iomanip> ——using std::setw; 使用时声明:#include <iostream> using namespace std; #include <iomanip> using std::setw; cout<<'s'<<setw(8)<

setw()函数使用,#include <iomanip> ——using std::setw;

使用时声明:

#include <iostream> using namespace std; #include <iomanip> using std::setw;

cout<<'s'<<setw(8)<<'a'<<endl; 则在屏幕显示 s        a  //s与a之间有7个空格,

上代码:

#include <iostream> using namespace std; #include <iomanip> using std::setw; int main () {     cout << "Element" << setw( 1 ) << "Value" << endl;     cout<<"1"<<setw(6)<<"1"<<endl;

   int n[ 10 ]; // n 是一个包含 10 个整数的数组    // 初始化数组元素              for ( int i = 0; i < 10; i++ )    {       n[ i ] = i + 100; // 设置元素 i 为 i + 100    }    cout << "Element" << setw( 1 ) << "Value" << endl;    // 输出数组中每个元素的值                         for ( int j = 0; j < 10; j++ )    {       cout << setw( 7 )<< j << setw( 1 ) << n[ j ] << endl;    }

   return 0; }

结果:

代码语言:javascript代码运行次数:0运行复制
Element        Value
1     1
Element        Value
      0          100
      1          101
      2          102
                10
      4          104
      5          105
      6          106
      7          107
      8          108
      9          109
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2024-12-16,如有侵权请联系 cloudcommunity@tencent 删除using函数数组includestd

#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格

本文地址:http://www.dnpztj.cn/biancheng/1263006.html

相关标签:无
上传时间: 2025-07-28 11:32:55
留言与评论(共有 8 条评论)
本站网友 中国外汇管理局
25分钟前 发表
上代码:#include <iostream> using namespace std; #include <iomanip> using std
本站网友 牛满
12分钟前 发表
本站网友 天津鲜花网
13分钟前 发表
上代码:#include <iostream> using namespace std; #include <iomanip> using std
本站网友 怀孕的过程
2分钟前 发表
如有侵权请联系 cloudcommunity@tencent 删除前往查看using函数数组includestd
本站网友 珍珠粉怎么做面膜
6分钟前 发表
上代码:#include <iostream> using namespace std; #include <iomanip> using std
本站网友 李国辉
7分钟前 发表
分享自作者个人站点/博客
本站网友 德阳电影院
1分钟前 发表