Question

In: Computer Science

what are stream manipulators in C++? write a detail note.

what are stream manipulators in C++? write a detail note.

Solutions

Expert Solution

Stream Manipulators are built in functions which are often used in conjunction with the insertion (<<) and extraction (>>) operators on stream objects.

The stream manipulators in C++ are given as:

  • endl

This manipulator has the same functionality as ‘\n’(newline character). But this also flushes the output stream.

Example

#include<iostream>
int main() {
   std::cout << "Hello" << std::endl << "World!";
}

Output

Hello
World!
  • setprecision

This manipulator changes floating-point precision.

Example

#include <iostream>
#include <iomanip>
int main() {
   const long double pi = 3.141592653589793239;
   std::cout << "default precision (6): " << pi << '\n'
             << "std::setprecision(10): " << std::setprecision(10) << pi << '\n';
}

Output

default precision (6): 3.14159
std::setprecision(10): 3.141592654
  • setw

This manipulator changes the width of the next input/output field.

Example

#include <iostream>
#include <iomanip>
int main() {
   std::cout << "no setw:" << 42 << '\n'
             << "setw(6):" << std::setw(6) << 42 << '\n'
             << "setw(6), several elements: " << 89 << std::setw(6) << 12 << 34 << '\n';
}

Output

no setw:42
setw(6):    42
setw(6), several elements: 89    1234

Related Solutions

what are stream manipulators in C++? Write at least 3 short example programs of stream manipulators.
what are stream manipulators in C++? Write at least 3 short example programs of stream manipulators.
Write a detail note on self organizing map
Write a detail note on self organizing map
Write a detail note on the duties and liabilities that are imposed on the professional engineers,...
Write a detail note on the duties and liabilities that are imposed on the professional engineers, by the “Code of Professional Ethics”, as approved by the Pakistan Engineering Council, to maintain, uphold and advance the honor and dignity of the engineering professional in Pakistan.
Please write code for C language Problem: Write a couple of functions to process arrays. Note...
Please write code for C language Problem: Write a couple of functions to process arrays. Note that from the description of the function you have to identify what would be the return type and what would be part of the parameter. display(): The function takes an int array and it’s size and prints the data in the array. sumArray(): It takes an int array and size, and returns the sum of the elements of the array. findMax(): It takes an...
Note- can you rewrite the code in C++. Circle Class c++ code Write a circle class...
Note- can you rewrite the code in C++. Circle Class c++ code Write a circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument . • setRadius. A mutator function for the radius variable. • getRadius. An acccssor function...
Write a comprehensive note on the process of transcription? Write a short note on how mature...
Write a comprehensive note on the process of transcription? Write a short note on how mature mRNA is produced in eukaryotes? What are the roles of loading buffer/loading dye, DNA marker and an ethidium bromide in a gel electrophoresis? During DNA isolation, how the DNA purification can be achieved and why the DNA purity is important in Agricultural biotechnology? What is the role of different restriction endonucleases in agricultural biotechnology? Write a note on the importance of molecular markers in...
You sold your motorcycle and accepted a note with the following cash flow stream as your...
You sold your motorcycle and accepted a note with the following cash flow stream as your payment. It pays you nothing now, $520 next year, and $5,000 for the three years after that (Years 2-4). What was the effective price you received for the motorcycle assuming an nominal interest rate of 9.1%? Show your answer to the nearest $.01. Do not use the $ or , signs in your answer.
Note- can you please rewrite the code in C++ Write a class declaration named Circle with...
Note- can you please rewrite the code in C++ Write a class declaration named Circle with a private member variable named radius. Write set and get functions to access the radius variable, and a function named getArea that returns the area of the circle. The area is calculated as 3.14159 * radius * radius
Write a short note on IMPLANTATION
Write a short note on IMPLANTATION
Write a comprehensive note on IT voilation
Write a comprehensive note on IT voilation
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT