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>
using namespace std;
string JustifyContentLeft(string line){
while (line.size()<20)
line+='&';
return line;
}
string JustifyContentRight(string line){
while (line.size()<20)
line='&'+line;
return line;
}
int main()
{
cout<<"Enter string: ";
string line;
getline(cin, line);
cout << "Justify Content Left: " << JustifyContentLeft(line) << endl;
cout << "Justify Content Right: " << JustifyContentRight(line) << endl;
return 0;
}
Comments
Leave a comment