The following program states you the Use of std::fill_n to fill the first five elements of characters with 'B' :
Code:
#include <iostream>
using std::cout;
using std::endl;
#include <algorithm>
#include <vector>
#include <iterator>
int main()
{
std::vector< char > chr( 10 );
std::ostream_iterator< char > output( cout, " " );
std::fill( chr.begin(), chr.end(), '5' );
std::fill_n( chr.begin(), 5, 'B' );
cout << "Vector chr after filling with 5s :\n";
std::copy( chr.begin(), chr.end(), output );
cout << endl;
return 0;
}
The output of the above :
Code:
Vector chars after filling with 5s :
B B B B B 5 5 5 5 5
Bookmarks