How to use setw() and setfill()

Hello everybody !!

i have a problem with setw() and setfill() in this function:

void inscrire()
{int Num;

cin>>Num;

string const nomfichier("etudiant2.txt");
ofstream fout(nomfichier.c_str(), ios::app);
if (fout!=NULL)
{
fout<<setw(10)<<setfill('*')<<Num<<endl;
}
else
{
cout<<"erreur : impossible d ouvrir le fichier "<<endl;
}
}

After running i get this : ****123456 in the file
But what i want is : 123456****
Look at this: http://www.cplusplus.com/reference/iostream/manipulators/

Especially 'Adustment format flags ("adjustfield" flags)' which is in your case 'left'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    int n = 123;

    cout<< setw(10)
        << setfill('*')
        << setiosflags(ios_base::left)
        << n
        << endl;

    return 0;
}
Thank's , but still have the problem, the setfill() function, just complete the string in the beginning not in the end !!!!!!!!!!!!!!
okkkkkk
thank's a lot :)

that's working :

void inscrire()
{int Num;
cin>>Num;

string const nomfichier("etudiant2.txt");
ofstream fout(nomfichier.c_str(), ios::app);
if (fout)
{
fout<<setw(10)<<setfill('*')<<left<<Num;
}
else
{
cout<<"erreur : impossible d ouvrir le fichier "<<endl;
}
}
Topic archived. No new replies allowed.