How to Right Justify Output in C++? Last Updated : 21 May, 2024 Comments Improve Suggest changes 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 How to Take Long String Input With Spaces in C++? In C++, we often take long strings with a lot of characters as inputs with spaces but if we use cin then our input gets terminated as soon as whitespace is encountered. In this article, we will discuss how to take long strings with spaces as input in C++. Take Long String Input With Spaces in C++To 2 min read How to Print an Array in C++? In C++, an array is a fixed-size linear data structure that stores a collection of elements of the same type in contiguous memory locations. In this article, we will learn how to print an array in C++. For Example, Input: array = {10, 20, 30, 40, 50}Output: Array Elements: 10 20 30 40 50Printing Arr 2 min read How to Read File into String in C++? In C++, file handling allows us to read and write data to an external file from our program. In this article, we will learn how to read a file into a string in C++. Reading Whole File into a C++ StringTo read an entire file line by line and save it into std::string, we can use std::ifstream class to 2 min read How to Reverse a String in Place in C++? In C++, reversing a string is a basic operation in programming that is required in various applications, from simple and complex algorithms. Reversing a string in place involves changing the characters of the string directly without using input-dependent additional storage. In this article, we learn 2 min read How to Validate User Input in C++ Validating the user input is very important for any program to ensure that the data being processed is correct and meaningful. In C++, various techniques can be used to validate the user input and in this article, we will learn how to validate the user input in C++. Validate User Input in C++To vali 4 min read Like