C++/Console/cout setiosflags


Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из C\C++ эксперт
Перейти к: навигация, поиск

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

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
  cout << setiosflags(ios::showpos);
  cout << setiosflags(ios::showbase);
  cout << 123 << " " << hex << 123;
  return 0;
}


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

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
  cout << setiosflags(ios::showpos);
  cout << setiosflags(ios::showbase);
  cout << 123 << " " << hex << 123;
  return 0;
}


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

 
#include <iostream> 
#include <iomanip> 
using namespace std; 
 
int main() 
{ 
  cout << setiosflags(ios::showpos) << setiosflags(ios::scientific) 
       << 123 << " " << 123.23; 
 
  return 0; 
}