1.memset 函数
函数作用:在一段内存块中填充某一个给定的值,常用于较大的对结构体和数组的清零操作。
代码
#include<iostream>
//#include"string.h"
using namespace std;
int main()
{
char str[10];
str[9] = 'w';
memset(str,97,9);
for(int i=0;i<10;i++){
cout<<str[i]<<" ";
}
return 0;
}
结果
输出:a a a a a a a a a w
代码
#include<iostream>
//#include"string.h"
using namespace std;
int main()
{
char str[10];
str[9] = 'w';
memset(str,97,sizeof(char)*10);
for(int i=0;i<10;i++){
cout<<str[i]<<" ";
}
return 0;
}
输出:a a a a a a a a a a
代码
#inclu