从文本文件中读取并使用 sizeof 结果计算整数的数量到 nan
Read from text file and count the number of integers using sizeof results to nan
我正在编写一个代码来计算从文本文件中读取的整数数,sizeof 函数显示"nan"。
double getSamplesize(vector<double> data)
{
int samplesize;
samplesize=sizeof(data);
cout<<samplesize<< endl;
}
在 int(main( 上:
cout<<"sample size: " << getsamplesize(arr) << endl;
预期输出应为:样本数量:(数量(但是我得到了
(数字(样本量:南
double getSamplesize(vector<double> data) ^^^^^^
您已声明该函数返回 double
。但是您的函数不会以 return
语句结尾。因此,程序的行为是未定义的,而未定义的行为就是您观察到的。
sizeof(data)
这将返回变量类型的大小。它与元素的数量或向量拥有的数组的大小完全无关。
预期输出应为:样本量:(数量(但我得到
程序中流式传输到标准输出的第一段代码是以下行:
cout<<samplesize<< endl;
因此,预期的输出不可能以"样本大小:"开头。
相关文章:
- 如何计算整数的十进制数字?
- 计算总和为 x 的所有整数子集(包括负数)
- 如何计算整数链中使用了多少次数字?
- 计算负基数的正非整数幂
- 通过在带有 C++ 的列表中添加连续元素来计算新的整数列表
- 我在c++中遇到了一个奇怪的错误,其中一个计算2个小整数加法的语句溢出到一个长值中
- 计算将整数n分解为4平方和的方法的数量
- 如何计算数组整数的总可能组合
- 当我们C++将两个数组的整数除以 时,如何获得浮点数计算;
- 计算 (64 位无符号整数) * (64 位无符号整数) 的商除以 2^64
- 为什么按位运算符在使用与整数中提供的位数相同的位数计算可能的最大范围时会产生错误
- 如何使用 C++ std 计算整数集合的前导零和尾随零
- 运算符"|"如何计算两个整数?
- 如何计算两个负整数 c++ 之间的总和
- 从文本文件中读取并使用 sizeof 结果计算整数的数量到 nan
- C 和 C++ 中的整数计算溢出
- 仅使用整数计算两条线的交点
- 一种在C++中执行基本 128 位整数计算的有效方法
- 算法C/C++:用n和d 32或64位整数计算(2^n)%d的最快方法
- 整数计算的二项式系数使用boost::math::binomial_coefficient,返回值为boost::mul