Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CPP how to format strings to align to the right side

I am looking for a simple CPP solution to align a string to the right size.

What do I mean by this?
here is an example:

the normal output would be

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

hello [message]
foo [message]

I would like it to output like this:

 hello [message]
   foo [message]

note: this is not for aligning a table but rather to know how to align a message by adding certain spaces to the left (or smth).

>Solution :

Like this ?

#include <iostream>
#include <iomanip>

int main()
{
    std::cout << std::setw(10) << "Hello" << " [message]" << std::endl ;
    std::cout << std::setw(10) << "foo" << " [message]" << std::endl ;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading