string___assign
#include <iostream>
#include <iterator>
#include <string> int main()
{
std::string s;
// assign(size_type count, CharT ch)
s.assign(, '=');
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, , c.length()-);
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", );
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)-);
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的更多相关文章
随机推荐
- iOS开发之判断横竖屏切换
/** * 当屏幕即将旋转的时候调用 * * @param toInterfaceOrientation 旋转完毕后的最终方向 * @param duration 旋转动画所花费的时间 */ ...
- BinarySearch的一些注意事项
BinarySearch原理比较简单,不过在处理实际问题的过程中需要注意几个小问题: 1. 找出有序数组中第一个为某特定值的数,以及没找到则返回-1 2. 找出有序数组中最后一个为某特定值的数,以及没 ...
- 3.Maven坐标和依赖
1.1 何为Maven坐标 正如之前所说的,Maven的一大功能就是管理项目依赖.为了能自动化地解析任何一个Java构件,Maven就必须将它们唯一标识,这就依赖管理的底层基础——坐标. 1.2 坐标 ...
- android开发之-软件设置保存-快速学会使用SharedPreferences篇-实测
我们在设计软件的时候,需要记录软件设置的基本信息,那么怎么来保存他们呢?我们可以使用SharedPreferences. SharedPreferences是一个xml文件,用来存储软件的常规设置 ...
- SQL Server特殊用法笔记
1. MERGE用法:关联两表,有则改,无则加 SQL语句: create table #AAA(id int,A int,AA int,AAA int,B int) create table #BB ...
- Spring+SpringMVC+MyBatis+easyUI整合优化篇(八)代码优化整理小记及个人吐槽
日常啰嗦 这两天也一直在纠结这一篇文章该写什么东西,前面临时加的两篇文章就有些打乱了整体节奏,这一篇又想去写一下代码层面优化的事情,可是也不太能抓住重要的点,不太确定从何入手,因为这件事情牵涉了太多技 ...
- 第四章 Struts2深入
4.1 Struts2架构 1.ActionMapper: 提供请求和Action之间的映射.根据请求查找是否存在对于的action,如有,翻译描述action映射的ActionM ...
- npm详解
一.npm介绍及安装 对于npm,大家多多少少都用过,作为一门技术,我想写篇博客记录一下,一起分享,一起学习. npm,是Node Package Manager的缩写,node的模块管理器,它是随同 ...
- R中基本统计图
一.条形图 1.安装包install.packages("vcd"); library(vcd);count<-table(Arthritis$Improved);#tabl ...
- 【stm32中断优先级--珍藏版】
看了这么久,一直不理解中断优先级,还有中断嵌套.stm32提供了多种嵌套方式,搞的我真是头昏脑涨. 今天终于看到了一个通俗解释中断优先级的博客.算是理解了一点吧. 原文地址:http://blog.s ...