Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

iomanip setiosflags() function in C++ with Examples

  • Last Updated : 10 Jun, 2021

The setiosflags() method of iomanip library in C++ is used to set the ios library format flags specified as the parameter to this method.
Syntax: 
 

setiosflags (ios_base::format_flag)

Parameters: This method accepts format_flag as a parameter which is the ios library format flag to be set by this method.
Return Value: This method does not returns anything. It only acts as stream manipulators.
Example 1:
 

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

CPP




// C++ code to demonstrate
// the working of setiosflags() function
 
#include <iomanip>
#include <ios>
#include <iostream>
 
using namespace std;
 
int main()
{
 
    // Initializing the integer
    int num = 50;
 
    // Using setiosflags()
    cout << "Setting showbase flag "
         << "using setiosflags: \n"
         << hex
         << setiosflags(ios::showbase)
         << num << endl;
 
    return 0;
}
Output: 
Setting showbase flag using setiosflags: 
0x32

 

Example 2:
 

CPP




// C++ code to demonstrate
// the working of setiosflags() function
 
#include <iomanip>
#include <ios>
#include <iostream>
 
using namespace std;
 
int main()
{
 
    // Initializing the integer
    int num = 50;
 
    // Using setiosflags()
    cout << "Setting showbase and uppercase"
         << " flag using setiosflags: \n"
         << hex
         << setiosflags(
                ios::showbase
                | ios::uppercase)
         << num << endl;
 
    return 0;
}
Output: 
Setting showbase and uppercase flag using setiosflags: 
0X32

 

Reference: http://www.cplusplus.com/reference/iomanip/setiosflags/
 




My Personal Notes arrow_drop_up
Recommended Articles
Page :