[英]Program unexpectedly quits for unknown reason (C++)
For some reason, whenever I run this program it exits at permute(permutater, length, lenth);
由于某种原因,每当我运行该程序时,它都会以permute(permutater, length, lenth);
退出permute(permutater, length, lenth);
. 。 This doesn't happen whenever I comment out the line and the function doesn't even run. 每当我注释掉该行并且函数甚至没有运行时,都不会发生这种情况。 Any help? 有什么帮助吗?
First thing I noticed - you're not initializing the index variable hor
. 我注意到的第一件事-您没有初始化索引变量hor
。
int permute(string permutater,int length,int lenth)
{
int hor,hor2,marker;
cout << length/lenth;
for (marker=0;marker !=(length/lenth);marker++)
{
hor2 = permutater[hor]; // <== hor is not initialized
permutater[hor] = permutater[hor-1];
permutater[hor] = hor2;
hor--;
cout << permutater;
}
}
hor2 = permutater[hor]; hor2 = permutater [hor];
What's the value of hor
? hor
的价值是什么?
I got the following compile errors with MSVC 我在使用MSVC时遇到以下编译错误
error C4716: 'permute' : must return a value
warning C4700: uninitialized local variable 'hor' used
Haven't got a chance to run it yet, but did you notice that you're missing return
in the permute(string permutater,int length,int lenth)
function. 还没有机会运行它,但是您是否注意到您在permute(string permutater,int length,int lenth)
函数中缺少return
值。
Also, please #include <string>
另外,请#include <string>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.