Read and output float : float output « Data Types « C++ Tutorial






#include <iostream>
using namespace std;
int main()
{
   int myInt;
   long myLong;
   double myDouble;
   float myFloat;
   unsigned int myUnsigned;
   char myWord[50];

   cout << "int: ";
   cin >> myInt;
   cout << "Long: ";
   cin >> myLong;
   cout << "Double: ";
   cin >> myDouble;
   cout << "Float: ";
   cin >> myFloat;
   cout << "Word: ";
   cin >> myWord;
   cout << "Unsigned: ";
   cin >> myUnsigned;

   cout << "\n\nInt:\t" << myInt << endl;
   cout << "Long:\t" << myLong << endl;
   cout << "Double:\t" << myDouble << endl;
   cout << "Float:\t" << myFloat << endl;
   cout << "Word: \t" << myWord << endl;
   cout << "Unsigned:\t" << myUnsigned << endl;

   cout << "\n\nInt, Long, Double, Float, Word, Unsigned: ";
   cin >> myInt >> myLong >> myDouble;
   cin >> myFloat >> myWord >> myUnsigned;
   cout << "\n\nInt:\t" << myInt << endl;
   cout << "Long:\t" << myLong << endl;
   cout << "Double:\t" << myDouble << endl;
   cout << "Float:\t" << myFloat << endl;
   cout << "Word: \t" << myWord << endl;
   cout << "Unsigned:\t" << myUnsigned << endl;


   return 0;
}








2.11.float output
2.11.1.Set precision for float number output
2.11.2.Set and clear the showpoint flag
2.11.3.Controlling the printing of trailing zeros and decimal points for floating-point values.
2.11.4.Read and output float
2.11.5.pad the field width with spaces and set the internal and showpos flags