Hey guys i'm working on a project that involves the user submitting a paragraph to me and then asking them to choose which alignment option they would like(see code) the problem is i can't the alignments to work and i'm pretty stumped, i tried checking out a different page that showed me how but its still not working. any help would be awesome!
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
int main()
{
std::string paragraph;
std::cout<<" Please, enter a full paragraph: ";
std::getline (std::cin,paragraph);
int adjustment = 0;
cout << " Please give me a numerical number from 1 to 4 for how you would like your paragraph to be formatted " <<"\n"<<"1.Left aligned, 2.Right aligned, 3.Center aligned, 4.Justify aligned: ";
cin >> adjustment;
switch(adjustment)
{
case 1 :
std::cout.width(6); std::cout << left << paragraph << "\n";
break;
case 2 :
std::cout.width(6); std::cout<< right << paragraph << "\n";
break;
case 3 :
std::cout.width(6); std::cout<< setw(20)<< paragraph << "\n";
break;
case 4 :
std::cout.width(6); std::cout<< std::internal << paragraph << "\n";
break;
default :
cout<<"Please enter a number from only 1 to 4"<<endl;
}
return 0;
}
The alignment settings for iostreams are for controlling the format of output within a field of a particular size (or width.) They are not sufficient for formatting paragraphs.
If the size (width) is smaller than the length of the output, it is ignored.
i understand what you are putting but i'm not quite sure how you would add this into the case statement while still prompting them for a paragraph, still quite new to c++
If you want to format paragraphs, you need to do it yourself. As I mentioned:
cire wrote:
The alignment settings for iostreams are for controlling the format of output within a field of a particular size (or width.) They are not sufficient for formatting paragraphs.