簡體   English   中英

程序由於未知原因意外退出(C ++)

[英]Program unexpectedly quits for unknown reason (C++)

由於某種原因,每當我運行該程序時,它都會以permute(permutater, length, lenth);退出permute(permutater, length, lenth); 每當我注釋掉該行並且函數甚至沒有運行時,都不會發生這種情況。 有什么幫助嗎?

我注意到的第一件事-您沒有初始化索引變量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];

hor的價值是什么?

我在使用MSVC時遇到以下編譯錯誤

error C4716: 'permute' : must return a value
warning C4700: uninitialized local variable 'hor' used

還沒有機會運行它,但是您是否注意到您在permute(string permutater,int length,int lenth)函數中缺少return值。

另外,請#include <string>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM