Namespaces
Variants

std:: left, std:: right, std:: internal

From cppreference.net
< cpp ‎ | io ‎ | manip
Input/output manipulators
Floating-point formatting
Integer formatting
Boolean formatting
Field width and fill control
internal left right
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)
Défini dans l'en-tête <ios>
(1)
(2)
std:: ios_base & internal ( std:: ios_base & str ) ;
(3)

Modifie le positionnement des caractères de remplissage dans un flux de sortie. left et right s'appliquent à tout type de sortie, internal s'applique aux sorties entières, à virgule flottante et monétaires. N'a aucun effet sur l'entrée.

1) Définit le adjustfield du flux str à left comme en appelant str. setf ( std:: ios_base :: left , std:: ios_base :: adjustfield ) .
2) Définit le adjustfield du flux str à right comme en appelant str. setf ( std:: ios_base :: right , std:: ios_base :: adjustfield ) .
3) Définit le adjustfield du flux str à internal comme en appelant str. setf ( std:: ios_base :: internal , std:: ios_base :: adjustfield ) .

Le paramètre par défaut initial pour les flux standards est équivalent à right .

Ceci est un manipulateur d'E/S. Il peut être appelé avec une expression telle que out << std :: left pour tout out de type std::basic_ostream ou avec une expression telle que in >> std :: left pour tout in de type std::basic_istream .

Table des matières

Paramètres

str - référence au flux d'E/S

Valeur de retour

str (référence au flux après manipulation).

Exemple

#include <iomanip>
#include <iostream>
#include <locale>
int main()
{
    std::cout.imbue(std::locale("en_US.utf8"));
    std::cout << "Default positioning:\n" << std::setfill('*')
              << std::setw(12) << -1.23  << '\n'
              << std::setw(12) << std::hex << std::showbase << 42 << '\n'
              << std::setw(12) << std::put_money(123, true) << "\n\n";
    std::cout << "Left positioning:\n" << std::left
              << std::setw(12) << -1.23  << '\n'
              << std::setw(12) << 42 << '\n'
              << std::setw(12) << std::put_money(123, true) << "\n\n";
    std::cout << "Internal positioning:\n" << std::internal
              << std::setw(12) << -1.23  << '\n'
              << std::setw(12) << 42 << '\n'
              << std::setw(12) << std::put_money(123, true) << "\n\n";
    std::cout << "Right positioning:\n" << std::right
              << std::setw(12) << -1.23  << '\n'
              << std::setw(12) << 42 << '\n'
              << std::setw(12) << std::put_money(123, true) << '\n';
}

Sortie :

Default positioning:
*******-1.23
********0x2a
***USD *1.23
Left positioning:
-1.23*******
0x2a********
USD *1.23***
Internal positioning:
-*******1.23
0x********2a
USD ****1.23
Right positioning:
*******-1.23
********0x2a
***USD *1.23

Voir aussi

modifie la largeur du champ d'entrée/sortie suivant
(fonction)
modifie le caractère de remplissage
(modèle de fonction)
contrôle si le préfixe est utilisé pour indiquer la base numérique
(fonction)