C++/Console/cout scientific

Материал из C\C++ эксперт
Перейти к: навигация, поиск

cout: change formats

<source lang="cpp">

  1. include <iostream>

using namespace std; int main() {

 // change formats
 cout.unsetf(ios::dec);
 cout.setf(ios::hex | ios::scientific);
 cout << 123.23 << " hello " << 100 << "\n";
 cout.setf(ios::showpos);
 cout << 10 << " " << -10 << "\n";
 cout. setf(ios::showpoint | ios::fixed);
 cout << 100.0;
 return 0;

}

      </source>


cout: number base, justification, and format flags

<source lang="cpp">

  1. include <iostream>

using namespace std; int main() {

 cout.setf(ios::hex, ios::basefield);
 cout << 300;  
 return 0;

}


      </source>


Displays the value 100 with the showpos and showpoint flags turned on

<source lang="cpp">

  1. include <iostream>

using namespace std; int main() {

 cout.setf(ios::showpoint);
 cout.setf(ios::showpos);
 cout << 100.0;
 return 0;

}


      </source>


Sets both the uppercase and scientific flags and clears the uppercase flag

<source lang="cpp">

  1. include <iostream>

using namespace std; int main() {

 cout.setf(ios::uppercase | ios::scientific);
 cout << 1010.112;                          
 cout.unsetf(ios::uppercase); // clear uppercase
 cout << endl << 1100.112; 
 return 0;

}


      </source>