c++函数中如何能在不传入数组内个数多少的情况下知道数组个数,主要不能用sizeof
应该不行吧,传入函数的数组只是个地址,不告诉它有多少个元素或者地址对应的内存空间有多长,应该算不出来的。
用库函数strlen实现
#include <iostream>
#include <string.h>
//strlen函数的头文件
using namespace std;
int main() {
char sz[10];
cout << "请输入一串数字:";
cin >> sz;
int len = strlen(sz), i; //计算字符串sz的长度,不包括'\0'在内
cout << "这个数是" << len << "位数" << endl;
system("pause");
return 0;
}
vector