1 三目表达式
if(a<b)
min=a;
else
min=b;
用三木表达式
min=(a<b)?a:b;
满足则a,不满足则b。
2 setw(int n)函数
只对紧接着的输出有效,紧接着的输出结束后又变回默认的域宽。
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << setw(3) << 1 << 1234 << endl;
cout << 1234 << setw(7) << 1234 << 12345 << endl;
cout << 1234 << setw(3) << 12345 << endl;
cout << 1234 << setw(4) << 123456 << 12 << setw(5) << 123 << endl;
return 0;
}

本文深入解析了C++中的三目表达式语法及其应用,并详细介绍了setw函数的功能与使用方法,通过具体代码示例展示了如何利用setw调整输出格式,适合初学者快速掌握这两个知识点。
6419

被折叠的 条评论
为什么被折叠?



