-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chapter 3: Streams 打印1.cpp
58 lines (48 loc) · 1.27 KB
/
Chapter 3: Streams 打印1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// 暴力法画出
// --------------------+----------------------+---------------------
// 1 | 137 | 2.71828
// 2 | 42 | 3.14159
// 3 | 7897987 | 1.608
// 4 | 1337 | 0.0110101
#include<iostream>
#include<fstream>
using namespace std;
const int COLUMN_NUM = 3;
const int LINE_NUM = 4;
const int COLUMN_WIDTH = 20;
// 打印 --------------------+----------------------+---------------------
void PrintHeader()
{
for(int column=0; column<COLUMN_NUM-1; ++column)
{
for(int i=0; i<COLUMN_WIDTH; ++i)
{
cout<<'-';
}
cout<<"-+-";
}
for(int i=0; i<COLUMN_WIDTH; ++i)
{
cout<<'-';
}
cout<<endl;
}
void PrintBody()
{
ifstream input("打开文件的绝对路径");
for(int i=0; i<LINE_NUM; ++i)
{
int intValue;
double doubleValue;
input>>intValue>>doubleValue;
cout<<setw(COLUMN_WIDTH)<<i+1<<" | "; // setw(20)的意思是加后面的(i+1)这个数字一共占20个字符。
cout<<setw(COLUMN_WIDTH)<<intValue<<" | ";
cout<<setw(COLUMN_WIDTH)<<doubleValue<<endl;
}
}
int main()
{
PrintHeader();
PrintBody();
return 0;
}