关于std::cout的异常
本帖最后由 bin554385863 于 2019-10-29 23:35 编辑#include <iostream>
//获取偶数因子
void func(int num, int *arr, int *n)
{
int count = 0;
if (num <= 0)//排除负数
{
std::cout << "DATE ERROR";
exit(1);
}
else
{
//查找偶数因子
for (size_t i = num; i >= 1; i--)
{
if (num % (i * 2) == 0)
{
count++;
}
}
*n = count;
count = 0;
for (size_t i = num; i >= 1; i--)
{
if (num % (i * 2) == 0)
{
int tmp = num / i;
arr = tmp;
count++;
}
}
}
}
//计算偶数因子的个数
int arrsize(int num)
{
int size = 0;
for (size_t i = 1; i <= num; i++)
{
if (num % (2 * i) == 0)
{
size++;
}
}
return size;
}
int main(int argc, char const *argv[])
{
int a = 1;
std::cin>>a;
for (int b = 0; a != 0; std::cin >> a)
{
int s = arrsize(a);
int ptr = {0};
func(a, ptr, &b);
std::cout<<b<<std::endl;//---------------------------用着一句正常
//std::cout<<a<<"有"<<b<<"偶数因子,分别是: ";//-----------------------------------换这一句就运行出错
for (size_t i = 0; i < s; i++)
{
std::cout << ptr << "";
}
std::cout<<'\n'<<std::endl;
}
return 0;
}
-------------------------------------------------------------------------
E:\Users\86184\Documents\Code>c:\Users\86184\.vscode\extensions\ms-vscode.cpptools-0.26.1\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-xjv21zb3.gvr --stdout=Microsoft-MIEngine-Out-1tluhllq.vmq --stderr=Microsoft-MIEngine-Error-anjenvq5.mdt --pid=Microsoft-MIEngine-Pid-an5hlhwz.f4m "--dbgExe=E:\My Program\MinGW\bin\gdb.exe" --interpreter=mi
96
10
2468121624324896
34
2
234
24
6
24681224
0
============================================================
#include <iostream>
//获取偶数因子
void func(int num, int *arr, int *n)
{
int count = 0;
if (num <= 0)//排除负数
{
std::cout << "DATE ERROR";
exit(1);
}
else
{
//查找偶数因子
for (size_t i = num; i >= 1; i--)
{
if (num % (i * 2) == 0)
{
count++;
}
}
*n = count;
count = 0;
for (size_t i = num; i >= 1; i--)
{
if (num % (i * 2) == 0)
{
int tmp = num / i;
arr = tmp;
count++;
}
}
}
}
//计算偶数因子的个数
int arrsize(int num)
{
int size = 0;
for (size_t i = 1; i <= num; i++)
{
if (num % (2 * i) == 0)
{
size++;
}
}
return size;
}
int main(int argc, char const *argv[])
{
int a = 1;
std::cin>>a;
for (int b = 0; a != 0; std::cin >> a)
{
int s = arrsize(a);
int ptr = {0};
func(a, ptr, &b);
//std::cout<<b<<std::endl;
std::cout<<a<<"有"<<b<<"偶数因子,分别是: ";//----------------------------------换这一句就出错
for (size_t i = 0; i < s; i++)
{
std::cout << ptr << "";
}
std::cout<<'\n'<<std::endl;
}
return 0;
}
-------------------------------------------------------------------------------------------------------------------------
E:\Users\86184\Documents\Code>c:\Users\86184\.vscode\extensions\ms-vscode.cpptools-0.26.1\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-2gbu1oh3.3nj --stdout=Microsoft-MIEngine-Out-wftrvwyt.h3h --stderr=Microsoft-MIEngine-Error-cbpl2yrx.dof --pid=Microsoft-MIEngine-Pid-ke3zm1dx.xaf "--dbgExe=E:\My Program\MinGW\bin\gdb.exe" --interpreter=mi
2
296
6
32
0
E:\Users\86184\Documents\Code>
------------------------------------------------------------
实在搞不明白 {:10_285:} {:10_285:}
自顶,逻辑应该没问题啊,
就那条cout语句调试结果是错误的
页:
[1]