# 36 Lecture

## Stream Manipulations

Stream manipulations, also known as manipulators, are functions that are used to modify the formatting and behavior of input and output streams in C++. Some common manipulations include setting the width and precision of output data, controlling

## Important Mcq's Midterm & Finalterm Prepration Past papers included

1. Which of the following stream manipulators is used to set the width of output data? A. setw() B. setwidth() C. setfill() D. setprecision()

1. What is the purpose of the setprecision() stream manipulator? A. To set the width of output data B. To set the number of decimal places for output data C. To skip whitespace when reading input data D. To set the fill character for output data

Answer: B. To set the number of decimal places for output data

1. Which of the following stream manipulators is used to control the format of numeric output? A. setprecision() B. setformat() C. setfill() D. setiosflags()

1. What is the purpose of the showpoint stream flag? A. To show the decimal point for floating-point output B. To show the sign of negative numbers C. To skip leading whitespace when reading input data D. To show trailing zeros for floating-point output

Answer: A. To show the decimal point for floating-point output

1. Which of the following stream manipulators is used to skip whitespace when reading input data? A. setw() B. setwidth() C. skipws D. noskipws

1. What is the purpose of the setfill() stream manipulator? A. To set the width of output data B. To set the number of decimal places for output data C. To skip whitespace when reading input data D. To set the fill character for output data

Answer: D. To set the fill character for output data

1. Which of the following stream manipulators is used to reset the format flags for a stream? A. resetiosflags() B. setiosflags() C. clear() D. setbase()

1. What is the purpose of the setw() and setfill() manipulators used together? A. To set the width of output data B. To set the number of decimal places for output data C. To skip whitespace when reading input data D. To set the fill character and width for output data

Answer: D. To set the fill character and width for output data

1. Which of the following stream manipulators is used to control the format of output data? A. setprecision() B. setiosflags() C. setfill() D. setw()

1. What is the purpose of the noshowpoint stream flag? A. To hide the decimal point for floating-point output B. To hide the sign of negative numbers C. To skip trailing whitespace when reading input data D. To hide trailing zeros for floating-point output

Answer: A. To hide the decimal point for floating-point output

## Subjective Short Notes Midterm & Finalterm Prepration Past papers included

1. What are stream manipulations in C++? Answer: Stream manipulations, also known as manipulators, are functions that are used to modify the formatting and behavior of input and output streams in C++.

2. How do you use the setw() manipulator to set the width of output data? Answer: You can use the setw() manipulator followed by an integer value to set the width of output data. For example: cout << setw(10) << "Hello";

3. What is the purpose of the setprecision() manipulator? Answer: The setprecision() manipulator is used to set the number of decimal places for floating-point output data.

4. How do you use the setiosflags() manipulator to set stream flags? Answer: You can use the setiosflags() manipulator followed by a flag constant to set stream flags. For example: cout << setiosflags(ios::fixed) << 3.14159;

5. What is the purpose of the skipws manipulator? Answer: The skipws manipulator is used to skip leading whitespace when reading input data.

6. How do you use the setfill() manipulator to set the fill character for output data? Answer: You can use the setfill() manipulator followed by a character value to set the fill character for output data. For example: cout << setfill('*') << setw(10) << "Hello";

7. What is the purpose of the resetiosflags() manipulator? Answer: The resetiosflags() manipulator is used to reset the format flags for a stream to their default values.

8. How do you use the noshowpoint manipulator to hide the decimal point for floating-point output data? Answer: You can use the noshowpoint manipulator to hide the decimal point for floating-point output data. For example: cout << noshowpoint << 3.14159;

9. What is the purpose of the setiosflags() manipulator with the ios::left flag? Answer: The setiosflags() manipulator with the ios::left flag is used to left-justify output data.

10. How do you use the setprecision() manipulator with fixed-point notation to set the number of decimal places for output data? Answer: You can use the setprecision() manipulator with the fixed-point notation to set the number of decimal places for output data. For example: cout << fixed << setprecision(2) << 3.14159;

In C++, streams are used to handle input and output operations. Stream manipulators are a set of functions that can be used to modify the behavior of input and output streams. Manipulators are used to set various attributes, such as the width of output data, the number of decimal places for floating-point data, the fill character for output data, and more. The setw() manipulator can be used to set the width of output data. It is followed by an integer value that specifies the width. The setprecision() manipulator is used to set the number of decimal places for floating-point output data. It is followed by an integer value that specifies the number of decimal places. The setiosflags() manipulator can be used to set stream flags. It is followed by a flag constant that specifies the flag to be set. The resetiosflags() manipulator is used to reset the format flags for a stream to their default values. The skipws manipulator is used to skip leading whitespace when reading input data. The setfill() manipulator is used to set the fill character for output data. It is followed by a character value that specifies the fill character. The noshowpoint manipulator can be used to hide the decimal point for floating-point output data. The setiosflags() manipulator with the ios::left flag is used to left-justify output data. The setprecision() manipulator with fixed-point notation can be used to set the number of decimal places for output data in fixed-point notation. Stream manipulators provide a convenient way to modify the formatting and behavior of input and output streams in C++. They are easy to use and can be combined to achieve the desired formatting and behavior.