次のような列を C++ で出力する必要があります。
Lower Upper
Line case case Digits Spaces Other
------ ------ ------ ------ ------ ------
ファイルの読み取りなどの結果を印刷する。
c++ で setw(6) を使用してワードラップを行う方法はありますか???
私のコードは次のようになります。
#include <iostream>
#include <iomanip>
using namespace std;
void printLines(); // declaring
int main(int argc, char *argv[]) {
// print table headings
cout << setw(6) << "Line" << setw(1) << " ";
cout << setw(6) << "Lower case" << setw(1) << " ";
cout << setw(6) << "Upper case" << setw(1) << " ";
cout << setw(6) << "Digits" << setw(1) << " ";
cout << setw(6) << "Spaces" << setw(1) << " ";
cout << setw(6) << "Other" << endl;
printLines();
};
// function to output 5 "lines" to divide the table headings from the data
void printLines() {
for (int i = 0; i < 6; i++) {
cout << setfill('-') << setw(6); // set output fill
cout << "-" << setfill(' ') << setw(1) << " ";
};
return;
};
しかし、私の出力は次のようになります。
Line Lower case Upper case Digits Spaces Other
------ ------ ------ ------ ------ ------
助言がありますか?ありがとう。