zoukankan      html  css  js  c++  java
  • string___assign

    #include <iostream>
    #include <iterator>
    #include <string>
     
    int main()
    {
      std::string s;
      // assign(size_type count, CharT ch)
      s.assign(4, '=');
      std::cout << s << '
    '; // "===="
     
      std::string const c("Exemplary");
      // assign(basic_string const& str)
      s.assign(c);
      std::cout << c << "==" << s <<'
    '; // "Exemplary == Exemplary"
     
      // assign(basic_string const& str, size_type pos, size_type count)
      s.assign(c, 0, c.length()-1);
      std::cout << s << '
    '; // "Exemplar";
     
      // assign(basic_string&& str)
      s.assign(std::string("C++ by ") + std::string("example"));
      std::cout << s << '
    '; // "C++ by example"
     
      // assign(charT const* s, size_type count)
      s.assign("C-style string", 7);
      std::cout << s << '
    '; // "C-style"
     
      // assign(charT const* s)
      s.assign("C-stylestring");
      std::cout << s << '
    '; // "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 << '
    '; // "C-style string"
     
      // assign(std::initializer_list<charT> ilist)
      s.assign({ 'C', '-', 's', 't', 'y', 'l', 'e' });
      std::cout << s << '
    '; // "C-style"
    }
    Output:
    ====
    Exemplary==Exemplary
    Exemplar
    C++ by example
    C-style
    C-style
    C-style string
    C-style
  • 相关阅读:
    优化tomcat——jvm
    深入理解jvm
    Too many open files
    Ubuntu 18.04 chrome安装
    Ubuntu 对比度调节
    SSH 开启,安装
    Ubuntu的Gnome美化
    snap占用/dev/loop0-/dev/loop11占用100%
    C题——Halting Problem(补题)
    H:有趣的试剂(1317)
  • 原文地址:https://www.cnblogs.com/lipenglin/p/4378834.html
Copyright © 2011-2022 走看看