2015-11-28 26 views
-1

遠慮:如果它是需要的話,我可以添加類定義。 問題:我得到一個STATUS_ACCESS_VIOLATION每當我試圖在我的程序運行此功能。我想知道發生了什麼事。我在某處出界嗎?如果我能自己推理出來,我會的。但我無法單獨解決它。我非常接近僱用某人爲我進行調試。這是值得我遺憾的。無論如何,這需要查看並給予一點TLC。提前致謝!爲什麼這個功能不斷崩潰?

int S_Rend::count(bitset<8> alpha, bitset<8> spec) { 

    int bn; 
    vector< bitset<8> > cnt; 
    bitset<8> curr; 
    int chmp; 

    eta = (alpha & spec); 
    theta = (alpha | spec); 

    cnt[0] = eta & alpha; 
    cnt[1] = eta | alpha; 
    cnt[2] = eta & spec; 
    cnt[3] = eta | spec; 
    cnt[4] = theta & alpha; 
    cnt[5] = theta | alpha; 
    cnt[6] = theta & spec; 
    cnt[7] = theta | spec; 
    cnt[8] = cnt[0] & cnt[5]; 
    cnt[9] = cnt[6] | cnt[1]; 
    cnt[10] = cnt[2] & cnt[7]; 
    cnt[11] = cnt[4] | cnt[3]; 

    for (int i=0;i<11;i++) 
     for (int j=i;j<=11;j++) { 
      curr = cnt[i]; 
      if (cnt[j] == curr) 
       bn++; 
      if (bn>chmp) 
       chmp=bn; 
     } 

    return chmp; 
} 

int S_Rend::s_render(ifstream& in, ofstream& out) { 

    int i, n; 
    int t; 
    int chk; 
    in >> lambda; 
    in >> size; 
    in >> delta; 
    in >> chk; 
    t=(int&)beta; 
    int bn=0; 

    while (size-1>=bn) { 
     t=s_nop((int&)t,0); 
     cred.push_back(t); 
     bn++;  
    } 

    if (cred[bn-1]==chk) 
     cout << "\nValidity Pass... Success!" << endl; 
    else { 
     printf("\nValidity Pass...Fail! %u != %u",cred[cred.size()-1],chk); 
     return 1; 
    } 

    cout << "\nWriting to Buffer..." << endl; 
    i=0; 
    spec = lambda; 
int f; 
while (bn-1>=0) { 
    alpha = (int&)cred[bn-1]; 
    f=count(alpha, spec); 
    eta = (int&)f; 
    spec ^= alpha^eta; 
    btrace.push_back(f); 
    cout << f << " "; 
    bn--; 
} 

    cout << "One more second..\n"; 

    while (i<=bn-1) { 
     delta = (int&)btrace[bn]; 
     out << (const char)(int&)delta; 
     i++; 
    } 

    cout << "\nBuffer Written... Exiting..\n"; 
    in.close(); 
    out.close(); 
    printf("*"); 
    return 0; 
} 
+2

當你使用一個調試器,該聲明(S)導致該問題?聲明中使用的變量的值是什麼? –

+0

你應該用這樣的線做什麼? 'delta =(int&)btrace [bn];'?你爲什麼要投射到一個int引用? – PaulMcKenzie

+0

請不要一次又一次重新發布相同的問題。另外,[tag:data-mining]顯然不是比特幣挖掘。 –

回答

2

此時: 而(BN){ 阿爾法=(INT &)名氣[BN]; F =計數(α,規格);

億==尺寸和大小== cred.size(),所以你讀ouside的載體。假設名氣是在啓動

+0

我改變了這一點,它沒有奏效,傑羅姆。這是別的。 – thexiv

1

空的最突出的問題是,你從一個向量寫入(和讀出)與外的界限指標:

int S_Rend::count(bitset<8> alpha, bitset<8> spec) 
{ 
    int bn; 
    vector< bitset<8> > cnt; 
    bitset<8> curr; 
    int chmp; 

    eta = (alpha & spec); 
    theta = (alpha | spec); 

    cnt[0] = eta & alpha; // <-- Illegal access 
    ... 
} 

好了,我們可以停在那兒。

std::vector不是尺寸,因此它不能容納的任何元件。最後行假定vector可容納至少一個項目(項目0)。因此這是未定義的行爲。

尺寸通過調用適當向量訪問元素之前push_backvector::resizevector::insertvector::emplace_back,或者通過發出尺寸除了其構建該載體的構造函數之一構建載體。

std::vector description

因爲它似乎你想要12個項目,那麼你就可以用12個項目建設它。

int S_Rend::count(bitset<8> alpha, bitset<8> spec) 
{ 
    int bn; 
    vector< bitset<8> > cnt(12); 
    bitset<8> curr; 
    int chmp; 

    eta = (alpha & spec); 
    theta = (alpha | spec); 

    cnt[0] = eta & alpha; // <-- ok 
    ... 
} 

此外,作爲調試助手,你也可以使用std::vector::at代替operator [ ]訪問矢量項目。使用at()將立即拋出std::out_of_bounds異常,表明您正在訪問帶有無效索引的向量(而不是程序繼續,因爲沒有任何錯誤)。


似乎可疑第二件事是你鑄造std::bitset爲int參考,反之亦然。正如你觀察到的,沒有演員,你會得到一個錯誤。使用C風格轉換來「關閉編譯器」並不是一個好主意,因爲你所做的只是繞過C++在編譯時所處的類型安全機制。

如果編譯器對你說「這不應該完成」,然後你通過發佈一個C風格的轉換覆蓋它,準備在你的程序顯示不穩定的行爲時承受後果。

若要在std::bitsetint之間進行正確轉換,可以使用此方法,即std::to_ulong

How to convert from bitset to an int

+0

我解決了所有這些問題,她像一匹加勒比馬匹hyuk一樣奔跑。但是我想知道,如果我只是使用'&'加密,那麼我怎樣才能用鑰匙取回?我找不到XOR加密驅逐艦。 – thexiv