C++ Printing Student Table Using iomanip
Posted by Samath
Last Updated: January 04, 2017

This program will print the information of students in a table. The iomanip library is used to format the table. 

#include <iostream>
#include <iomanip>

using namespace std;
int main()
{

  cout << "Students Table:" << endl;
	cout << setfill('-') << setw(1) << "+" << setw(15) << "-" << setw(1) << "+" << setw(15) << "-" << setw(1) << "+" << setw(5) << "-" << setw(1) << "+" << endl;
	cout << setfill(' ') << setw(1) << "|" << setw(15) << left << "First Name" << setw(1) << "|" << setw(15) << left << "Last Name" << setw(1) << "|"  << setw(5) << left << "Age" << setw(1) << "|" << endl;
	cout << setfill('-') << setw(1) << "+" << setw(15) << "-" << setw(1) << "+" << setw(15) << "-" << setw(1) << "+" << setw(5) << "-" << setw(1) << "+" << endl;
	cout << setfill(' ') << setw(1) << "|" << setw(15) << left << "John" << setw(1) << "|" << setw(15) << left << "Brown" << setw(1) << "|"  << setw(5) << left << "27" << setw(1) << "|" << endl;
	cout << setfill('-') << setw(1) << "+" << setw(15) << "-" << setw(1) << "+" << setw(15) << "-" << setw(1) << "+" << setw(5) << "-" << setw(1) << "+" << endl;
	cout << setfill(' ') << setw(1) << "|" << setw(15) << left << "Mike" << setw(1) << "|" << setw(15) << left << "Smith" << setw(1) << "|"  << setw(5) << left << "22" << setw(1) << "|" << endl;
	cout << setfill('-') << setw(1) << "+" << setw(15) << "-" << setw(1) << "+" << setw(15) << "-" << setw(1) << "+" << setw(5) << "-" << setw(1) << "+" << endl;
	cout << setfill(' ') << setw(1) << "|" << setw(15) << left << "Paul" << setw(1) << "|" << setw(15) << left << "Walker" << setw(1) << "|"  << setw(5) << left << "19" << setw(1) << "|" << endl;
	cout << setfill('-') << setw(1) << "+" << setw(15) << "-" << setw(1) << "+" << setw(15) << "-" << setw(1) << "+" << setw(5) << "-" << setw(1) << "+" << endl;

	return 0;
}