How to Manipulate cout Object using C++ IOS Library?28 Aug 2024 | 4 min read The C++ ios base class includes aspects for formatting cout objects that display various formatting characteristics. Using class scope static constants, the following ios base class can style cout object to display trailing decimal points, add + before positive integers, and various other formatting capabilities. Static Constants for Class Scope:Class scope static constants defined in the ios base class declaration assist in configuring various formatting capabilities. The scope resolution operator (::) is used with the constant name in class scope. Individual bits known as flags are class scope static constants declared in the ios base class. To activate formatting abilities, set the flag or bit to 1, which signifies that the bit is set to 1. There are two kinds of class scope static constants:
Independent flags:Class scope static independent formatting constants and their functions are shown in the table below.
setf(): The ios base class includes a setf() function for setting the particular bit or flag. The Setf() function returns two prototypes. Syntax: Parameters:
The following C++ program follows the setf() function: C Programming Language: Output The output is: +31.43 Non-Independent Flags:The table below shows various Class scope static non-independent formatting constants and their function-specific values. 1. ios_base::adjustfield
2. ios_base::floatfield
3. ios_base::basefield
static class scope Fields are going to serve as the second argument to specify which bits to clear, while constants will act as the first argument to specify which bits to set. Using the second prototype, we will call the setf() function to format the cout object. Syntax- Parameters:
The C++ code to accomplish the aforesaid strategy is provided below- C++ Program: Output The Output is: 31.4300 unsetf(): The ios_base class includes an unsetf() function that can be used to bring back the initial result. The setf() function sets a bit to 1 and unsetf() returns it to 0. Syntax: void unsetf (fmtflags); Parameters:
The C++ code for implementing the unsetf() function is shown below: C++ Program: Output The resulted number: 31.4300 The original number: 31.43 Next TopicSliding Window Algorithm in C++ |
In today's world, computer networks play an important role in the data transfer field. It is a subject that each programmer should know of. Under the computer network, socket programming is one of the most important topics in the programming world. In this topic, we are...
11 min read
Linear Equation is a basic concept in mathematics and science. Linear equations are important in many disciplines, such as computer science, economics, physics, and engineering. It is necessary to express systems of linear equations in matrix form to solve them quickly. What is a System of Linear...
4 min read
Bitwise XOR operator is also known as Exclusive OR It is denoted by using the '^' As the name depicts, it works on the bit level of the operands. Bitwise XOR operator has come under the category of Bitwise operators. In the bitwise exclusive OR operator (XOR), two operands are...
8 min read
An exception is an unexcepted event that occurs during the execution of the program that stops the normal flow of the program. Two types of exceptions are checked and unchecked exceptions. Checked exceptions are compile-time exceptions because the compiler checks these exceptions during compile-time, whereas the...
4 min read
In this article, we will discuss the top 10 most used inbuilt C++ functions for Competitive Programming. Introduction of Inbuilt C++ Functions In C++, integrated features are generally called general library features or features furnished via the C++ Standard Template Library (STL). These features cover an extensive variety...
9 min read
Addressing local variable retrieval of different functions in C++ is important and is the heart of the program's variable scope, function call, and data sharing. In C++, local variables can be declared only within a specific block of code, usually in the body of a particular...
8 min read
In this article, we will discuss the difference between C++ and GO. But before discussing their differences, we must know about C++ and Go with their examples and uses. What is the C++ programming language? C++ is a high-level and general-purpose programming language that was created as an...
4 min read
In this article, we will discuss the multiplication table programs in C++ with different cases. Case 1: Take a number from the user as input, and print the multiplication table for that number. C++ program: #include<iostream> using namespace std; int main(){ int number; cout<< "Enter the...
4 min read
C++ class to ent object copies A C++ class instance should occasionally not be cloned at all. A non-copyable mixin, a private copy constructor and assignment operator, or the removal of those particular member functions are the three approaches to stop such object copies. It is not appropriate...
4 min read
In this example, we will discuss a C++ program to show runtime exceptions. But before discussing the implementation the runtime exceptions, we must know about the exceptions or exception handling in C++. Exceptions in C++: An exception in C++ is a problem that occurs while a program is...
4 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India