Namespaces
Variants

std:: showbase, std:: noshowbase

From cppreference.net
< cpp ‎ | io ‎ | manip
Input/output manipulators
Floating-point formatting
Integer formatting
showbase noshowbase
Boolean formatting
Field width and fill control
Other formatting
Whitespace processing
Output flushing
Status flags manipulation
Time and money I/O
(C++11)
(C++11)
(C++11)
(C++11)
Quoted manipulator
(C++14)
Definiert im Header <ios>
std:: ios_base & showbase ( std:: ios_base & str ) ;
(1)
std:: ios_base & noshowbase ( std:: ios_base & str ) ;
(2)
1) Aktiviert das showbase -Flag im Stream str , als ob durch Aufruf von str. setf ( std:: ios_base :: showbase ) .
2) Deaktiviert das showbase -Flag im Stream str , als ob durch Aufruf von str. unsetf ( std:: ios_base :: showbase ) .

Dies ist ein I/O-Manipulator, er kann mit einem Ausdruck wie out << std :: showbase für jedes out vom Typ std::basic_ostream oder mit einem Ausdruck wie in >> std :: showbase für jedes in vom Typ std::basic_istream aufgerufen werden.

Das showbase -Flag beeinflusst das Verhalten der Integer-Ausgabe (siehe std::num_put::put ), monetärer Eingabe (siehe std::money_get::get ) und monetärer Ausgabe (siehe std::money_put::put ).

Inhaltsverzeichnis

Parameter

str - Referenz auf I/O-Stream

Rückgabewert

str (Referenz auf den Stream nach der Manipulation).

Hinweise

Wie in std::num_put::put spezifiziert, verhält sich das showbase-Flag bei der Ganzzahlausgabe wie der #-Formatbezeichner in std::printf , was bedeutet, dass das numerische Basispräfix nicht hinzugefügt wird, wenn der Wert Null ausgegeben wird.

Beispiel

#include <iomanip>
#include <iostream>
#include <locale>
#include <sstream>
int main()
{
    // showbase beeinflusst die Ausgabe von Oktal- und Hexadezimalzahlen
    std::cout << std::hex
              << "showbase: " << std::showbase << 42 << '\n'
              << "noshowbase: " << std::noshowbase << 42 << '\n';
    // sowie Ein- und Ausgabe von Geldbeträgen
    std::locale::global(std::locale("en_US.UTF8"));
    long double val = 0;
    std::istringstream("3.14") >> std::showbase >> std::get_money(val);
    std::cout << "Mit showbase ergibt das Parsen von 3.14 als Geldbetrag " << val << '\n';
    std::istringstream("3.14") >> std::noshowbase >> std::get_money(val);
    std::cout << "Ohne showbase ergibt das Parsen von 3.14 als Geldbetrag " << val << '\n';
}

Ausgabe:

showbase: 0x2a
noshowbase: 2a
With showbase, parsing 3.14 as money gives 0
Without showbase, parsing 3.14 as money gives 314

Siehe auch

löscht die angegebenen ios_base-Flags
(Funktion)
setzt die angegebenen ios_base -Flags
(Funktion)