C++/Console/cout setiosflags

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

cout: set ios flags, ios::showpos, ios::showbase

<source lang="cpp">

  1. include <iostream>
  2. include <iomanip>

using namespace std; int main() {

 cout << setiosflags(ios::showpos);
 cout << setiosflags(ios::showbase);
 cout << 123 << " " << hex << 123;
 return 0;

}


      </source>


setiosflags(): set the format flags related to a stream

<source lang="cpp">

  1. include <iostream>
  2. include <iomanip>

using namespace std; int main() {

 cout << setiosflags(ios::showpos);
 cout << setiosflags(ios::showbase);
 cout << 123 << " " << hex << 123;
 return 0;

}


      </source>


Use setiosflags(): ios::showpos, ios::scientific

<source lang="cpp">


  1. include <iostream>
  2. include <iomanip>

using namespace std;

int main() {

 cout << setiosflags(ios::showpos) << setiosflags(ios::scientific) 
      << 123 << " " << 123.23; 

 return 0; 

}

      </source>