• 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
  • 相关阅读:
    NET CORE 数据库迁移
    VUE3.0 解析svg文件
    关于ElementUI的样式不生效
    git命令
    vue 2.x的跨域问题
    Putty 重新启动 linux sqlserver服务
    aspnetcore之session
    Syncfusion 在 core 的架构
    TortoiseSVN创建/合并分支
    正则表达式知识点整理
  • 原文地址:https://www.cnblogs.com/lipenglin/p/4378834.html
Copyright © 2020-2023  润新知