옵션 |
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
int main() {
int size, line;
ofstream fout;
ifstream fin;
string temp;
fout.open("test2.txt");
cout << "Please enter the table size: ";
cin >> size;
fout << " ";
for (int column = 1; column <= size; column++)
fout << setw(4) << column;
fout << "n";
fout << " +";
for (int column = 1; column <= size; column++)
fout << "-----";
fout << "n";
for (int row = 1; row <= size; row++) {
fout << setw(4) << row << " |";
for (int column = 1; column <= size; column++)
fout << setw(4) << row * column;
fout << "n";
}
fout.close();
cout << "보고 싶은 줄의 번호를 입력해주세요: ";
cin >> line;
fin.open("test2.txt");
getline(fin, temp);
cout << temp << endl;
}
곱셈표 만든건데 5 입력하면
1 2 3 4 5
+-------------------------
1 | 1 2 3 4 5
2 | 2 4 6 8 10
3 | 3 6 9 12 15
4 | 4 8 12 16 20
5 | 5 10 15 20 25