/* * iostream_setiosflags.cpp * * Created on: 2013-9-30 * Author: Administrator */ #if 0 #include<iostream.h> #include<iomanip.h> int main(void) { double values[] = {5.99,3.56,25.5,1.88}; char *names[] = {"苹果" , "梨子", "莲雾", "香蕉"}; cout << "设置对齐方式举例:" << endl; for (int i = 0; i < 4; ++i) { /* 输出左对齐 宽度为6 */ cout << setiosflags(ios::left) << setw(6) << names[i] /* 这里的resetiosflags(ios::left) 的作用是 * 清除左对齐....这样输出又是按默认的右对齐来输出了 */ << resetiosflags(ios::left) << setw(10) << values[i] << endl; } cout << "\n other method\n\n"; for (int i = 0; i < 4; ++i) { /*或者用下面的这种方法也用达到同样的效果*/ cout << left << setw(6) << names[i] << right << setw(10) << values[i] << endl; } return 0; } #endif |
|
来自: 望穿墙 > 《iostream》