fill

来源:互联网 发布:部落冲突升级数据大全 编辑:程序博客网 时间:2024/05/22 08:13
#include <iostream>#include <cassert>#include <algorithm>#include <vector>#include <string>using namespace std;int main(){  string s("Hello there");  vector<char> vector1(s.begin(), s.end());  // Fill first 5 positions of vector1 with X's:  fill(vector1.begin(), vector1.begin() + 5, 'X');  vector<char>::iterator pos;  for (pos=vector1.begin(); pos!=vector1.end(); ++pos) {        cout << *pos << ' ';  }  return 0;}/* X X X X X   t h e r e  */        
#include <iostream>
using std::cout;
using std::endl;

#include <algorithm> // algorithm definitions
#include <vector>    // vector class-template definition
#include <iterator>  // ostream_iterator

int main()
{
   std::vector< char > chars10 );
   std::ostream_iterator< char > outputcout, " " );
   std::fillchars.begin(), chars.end()'5' )// fill chars with 5s

   cout << "Vector chars after filling with 5s:\n";
   std::copychars.begin(), chars.end(), output );
   cout << endl;
   return 0;
}

/* 
Vector chars after filling with 5s:
5 5 5 5 5 5 5 5 5 5

 */  
原创粉丝点击