How to Right Justify Output in C++? Last Updated : 21 May, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In C++, the outputs produced by the program are by default to the left of the screen. In this article, we will learn how to right justify the output in C++. Example: Input:float x= 123.45float y= 6.7899Output: 123.45 6.7899 // justified on the console’s right side.Right Justifying the Output in C++To right justify the output in C++, we can use the std::right function which is one of the stream manipulators that sets the position of fill characters in conjunction with the std::setw manipulator function, which sets the stream width to the specified number of characters passed as an integral argument to this method. C++ Program to Right Justify the Output The below program demonstrates how we can justify the output values on the right side of the console in C++. C++ // C++ program to right justify the output #include <iomanip> // for input-output manipulation #include <iostream> using namespace std; int main() { // Declare and initialize floating-point variables. float x = 123.45; float y = 6.7899; float z = 34.789; // Print each floating-point number with a width of 10 // and aligned to the right. cout << setw(50) << right << x << endl; cout << setw(50) << right << y << endl; cout << setw(50) << right << z << endl; return 0; } Output 123.45 6.7899 34.789 Time Complexity: O(1)Auxilliary Space: O(1) Comment More infoAdvertise with us Next Article How to Right Justify Output in C++? R rahulkatr5460 Follow Improve Article Tags : C++ Programs C++ cpp-ios cpp-manipulators CPP Examples +1 More Practice Tags : CPP Similar Reads How to Take Multiple Line String Input in C++? In C++, taking string input is a common practice but the cin is only able to read the input text till whitespace. In this article, we will discuss how to read the multiple line of text input in C++. For Example, Input:Enter Your Text: This is amultiline text.Output:You Have Entered:This is amultilin 2 min read How to Take Operator as Input in C++? Operators are symbols that specify some kind of operation. In C++, we sometimes need to take operators as user input mainly to perform mathematical operations. In this article, we will learn how to take operators as user input in C++. Operators as Input in C++To take operators (like +,-,*,/ etc) as 2 min read How to Reverse a String in C++? Reversing a string means replacing the first character with the last character, second character with the second last character and so on. In this article, we will learn how to reverse a string in C++.ExamplesInput: str = "Hello World"Output: dlroW olleHExplanation: The last character is replaced by 2 min read How to Read a Line of Input Text in C++? In C++, we often need to take input from the user by reading an input text line by line but the cin method only takes input till whilespace. In this article, we will look at how to read a full line of input in C++. For Example, Input: This is a text.Output: Entered Text: This is a text.Taking a Line 2 min read Convert char* to std::string in C++ Strings are generally represented as an instance of std::string class in C++. But the language also supports the older C-Style representation where they are represented as array of characters (char* or char[]) terminated by null character '\0'. In this article, we will learn how to convert the char* 3 min read Like