C++小知识点

版权声明:未经允许禁止转载。转载请联系我WX:yuyi5453。并且注明出处 https://blog.csdn.net/weixin_40532377/article/details/83960018

1.初始化二维数组尽量

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string st;
	cin>>st;
	cout<<st.length()<<endl;
	cout<<sizeof(st)<<endl; 
	cout<<sizeof(char)<<endl;
	cout<<sizeof(st)/sizeof(char)<<endl;
//	cout<<strlen(st)<<endl;  无
	
	char s[100];
	scanf("%s",s);
	cout<<strlen(s)<<endl;
	cout<<sizeof(s)<<endl;
//	cout<<s.length()<<endl;  无
}


//result:
123
3
8
1
8
123
3
100

不要用memset,使用fill(f[0], f[0]+N*N, k)。而且memset只能初始化为0,而fill可以初始化成任意值

猜你喜欢

转载自blog.csdn.net/weixin_40532377/article/details/83960018