Q. The function contain in the ios class to set width

  • (A) width()
  • (B) precision()
  • (C) fill()
  • (D) setf()
πŸ’¬ Discuss
βœ… Correct Answer: (A) width()
Explanation:

In C++ (especially with <iostream>), the ios class provides various functions to control the formatting of input and output. Here's what each option does:

width()
 Sets the field width (i.e., the minimum number of characters to be used for the next output).
βœ… This is used to set the width.

precision()
 Sets the number of digits to display after the decimal point for floating-point values.

fill()
 Sets the character used to fill unused width space (default is space ' ').

setf()
 Sets format flags (e.g., std::ios::left, std::ios::right, std::ios::fixed, etc.).

βœ… Correct Answer: (A) width()

std::cout.width(10); // sets width to 10 for the next output
std::cout << 123 << std::endl;
Explanation by: Mr. Dubey

In C++ (especially with <iostream>), the ios class provides various functions to control the formatting of input and output. Here's what each option does:

width()
 Sets the field width (i.e., the minimum number of characters to be used for the next output).
βœ… This is used to set the width.

precision()
 Sets the number of digits to display after the decimal point for floating-point values.

fill()
 Sets the character used to fill unused width space (default is space ' ').

setf()
 Sets format flags (e.g., std::ios::left, std::ios::right, std::ios::fixed, etc.).

βœ… Correct Answer: (A) width()

std::cout.width(10); // sets width to 10 for the next output
std::cout << 123 << std::endl;

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
116
Total Visits
πŸ“½οΈ
2 y ago
Published
πŸŽ–οΈ
Ranjeet
Publisher
πŸ“ˆ
99%
Success Rate