Develop a C++ program to display the string in left and right justifications. Specify the width as 20 and consider the special character to be filled as ‘&’.
#include <iostream>
#include <string>
#include <iomanip>
void leftJustification(std::string arg) {
std::cout << std::setfill('&') <<std::setw(20)<<std::left<< arg << std::endl;
}
void rightJustification(std::string arg) {
std::cout << std::setfill('&') << std::setw(20) << std::right << arg << std::endl;
}
int main()
{
std::cout << "Enter example string: ";
std::string str;
std::cin>>str;
std::cout << "Example left justification string"<<std::endl;
leftJustification(str);
std::cout << "Example right justification string" << std::endl;
rightJustification(str);
return 0;
}
Comments
Leave a comment