码迷,mamicode.com
首页 > 其他好文 > 详细

string___assign

时间:2015-03-30 20:39:54      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

#include <iostream>
#include <iterator>
#include <string>
 
int main()
{
  std::string s;
  // assign(size_type count, CharT ch)
  s.assign(4, =);
  std::cout << s << \n; // "===="
 
  std::string const c("Exemplary");
  // assign(basic_string const& str)
  s.assign(c);
  std::cout << c << "==" << s <<\n; // "Exemplary == Exemplary"
 
  // assign(basic_string const& str, size_type pos, size_type count)
  s.assign(c, 0, c.length()-1);
  std::cout << s << \n; // "Exemplar";
 
  // assign(basic_string&& str)
  s.assign(std::string("C++ by ") + std::string("example"));
  std::cout << s << \n; // "C++ by example"
 
  // assign(charT const* s, size_type count)
  s.assign("C-style string", 7);
  std::cout << s << \n; // "C-style"
 
  // assign(charT const* s)
  s.assign("C-style\0string");
  std::cout << s << \n; // "C-style"
 
  char mutable_c_str[] = "C-style string";
  // assign(InputIt first, InputIt last)
  s.assign(std::begin(mutable_c_str), std::end(mutable_c_str)-1);
  std::cout << s << \n; // "C-style string"
 
  // assign(std::initializer_list<charT> ilist)
  s.assign({ C, -, s, t, y, l, e });
  std::cout << s << \n; // "C-style"
}
Output:
====
Exemplary==Exemplary
Exemplar
C++ by example
C-style
C-style
C-style string
C-style

 

string___assign

标签:

原文地址:http://www.cnblogs.com/lipenglin/p/4378834.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!