C++ fill 和memset
以下内容来自www.cplusplus.com---------------------------------------------------
FILL:
template <class ForwardIterator, class T>
void fill (ForwardIterator first, ForwardIterator last, const T& val);
Assigns val to all the elements in the range [first,last).
The behavior of this function template is equivalent to:
|
|
void * memset ( void * ptr, int value, size_t num );
Fill block of memorySets the first num bytes
of the block of memory pointed by ptr to the specified value (interpreted as an unsigned char).------------------------------------------------------------------------------------------------------
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
int test[100];
fill(test,test+100,1);
cout<<"case 1:"<<endl;
for(int i=0;i<100;i++)
cout<<test[i]<<" ";
cout<<endl;
memset(test,1,sizeof(test));
cout<<"case 2:"<<endl;
for(int i=0;i<100;i++)
cout<<test[i]<<" ";
cout<<endl;
memset(test,1,100*sizeof(int));
cout<<"case 3:"<<endl;
for(int i=0;i<100;i++)
cout<<test[i]<<" ";
cout<<endl;
}
C++ fill 和memset的更多相关文章
- fill与memset的区别
fill 的头文件是<iostream> 命名空间是std: 在memset(a,0(-1),sizeof(a))全部初值定为0或-1时两者是没有多大区别; 但是在初值为其他值得时候就不同 ...
- fill和memset的区别
https://blog.csdn.net/xs18952904/article/details/75195412 memset只能初始化成为0或者-1,其他都要用fill来完成. #include& ...
- 【C++】fill函数,fill与memset函数的区别
转载自:https://blog.csdn.net/liuchuo/article/details/52296646 memset函数 按照字节填充某字符在头文件<cstring>里面fi ...
- C++中std::fill/std::fill_n的使用
There is a critical difference between std::fill and memset that is very important to understand. st ...
- fill 的用法
博客 : http://blog.csdn.net/liuchuo/article/details/52296646 fill函数的作用是:将一个区间的元素都赋予val值.函数参数:fill(vec. ...
- 【ACM/ICPC2013】线段树题目集合(一)
前言:前一段时间在网上找了一个线段树题目列表,我顺着做了一些,今天我把做过的整理一下.感觉自己对线段树了解的还不是很深,自己的算法能力还要加强.光练代码能力还是不够的,要多思考.向队友学习,向大牛学习 ...
- HDU 1045(Fire Net)题解
以防万一,题目原文和链接均附在文末.那么先是题目分析: [一句话题意] 给定大小的棋盘中部分格子存在可以阻止互相攻击的墙,问棋盘中可以放置最多多少个可以横纵攻击炮塔. [题目分析] 这题本来在搜索专题 ...
- CDOJ 1270 Playfair
模拟题,代码写得比较乱... #include<cstdio> #include<cstring> #include<cmath> #include<queu ...
- PAT A1004 Counting Leaves (30 分)——树,DFS,BFS
A family hierarchy is usually presented by a pedigree tree. Your job is to count those family member ...
随机推荐
- hihocoder 神奇字符串
思路: 暴力,模拟. 实现: #include <iostream> #include <algorithm> #include <cstdio> #include ...
- CCF|分蛋糕|Java
import java.util.Scanner; public class tyt { public static void main(String[] args) { Scanner in = n ...
- Android EditText 输入金额(小数点后两位)
EditText edit = new EditText(context); InputType.TYPE_NUMBER_FLAG_DECIMAL //小数点型 InputType.TYPE_CLAS ...
- 在 Windows Server 上搭建 *** 服务端(转载加亲测)
转载自:https://diveng.io/build-shadowsocks-server-on-windows-server.html 下面的教程建议大家使用第一种方法安装,说是比较简单.我则使用 ...
- workstation服务丢失 共享打不开 0x80070035
这个问题困扰一个星期了,希望能帮到人.
- bash之数组
Bash 提供索引和联想的一维数组变量.可用作任何变量 索引的数组 :内置的声明将显式声明数组.有没有最大限制 一个数组,也没有要求成员将索引或连续分配的大小.索引的数组 引用使用 (包括算术表达式) ...
- WebDAV协议
WebDAV是一项基于 Http1.1 协议的通信协议.它扩展了HTTP 1.1,在Get.Post.Put.Delete 等HTTP标准方法外添加了新方法,使应用程序可对Web Server直接读写 ...
- 单文件组件.vue---父子组件通信
每一个.vue 文件就是一个 组件,组件和组件相互组合,就成了一个应用,这就涉及到的组件和组件之间的通信,最常用的就是父子之间的通信.在vue 中, 在一个组件中通过 import 引入另一个组件,这 ...
- Mac OS X 中安装 brew
不想被误导?直接看官方文档: http://mxcl.github.com/homebrew/ 先安装Git,打开一个shell cd /usr/local sudo mkdir homeb ...
- mac vim编辑器常用操作快捷方式
0 行首$ (shift+6)行尾gg 文首G(shift+g) 文尾A(Shift+a)文尾,并编辑ctrl+f 向上翻页ctrl+b 向下翻页ctrl+u 向上翻半页ctrl+d 向下翻半页数字+ ...