BingoBoard分段故障 我一直在尝试用我在C++中创建的这个BIGO板来进行分割错误。Valgrind没有告诉我更多: ==2734== Memcheck, a memory error detector ==2734== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al. ==2734== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info ==2734== Command: ./Bingo ==2734== ==2734== Invalid read of size 1 ==2734== at 0x5D0A436: vfprintf (vfprintf.c:1620) ==2734== by 0x5DBF8ED: __printf_chk (printf_chk.c:37) ==2734== by 0x400FC0: generate(int, int) (in /home/holland/Code/cpp/Bingo-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Release/Bingo) ==2734== by 0x400B69: main (in /home/holland/Code/cpp/Bingo-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Release/Bingo) ==2734== Address 0x62 is not stack'd, malloc'd or (recently) free'd ==2734== ==2734== ==2734== Process terminating with default action of signal 11 (SIGSEGV) ==2734== Access not within mapped region at address 0x62 ==2734== at 0x5D0A436: vfprintf (vfprintf.c:1620) ==2734== by 0x5DBF8ED: __printf_chk (printf_chk.c:37) ==2734== by 0x400FC0: generate(int, int) (in /home/holland/Code/cpp/Bingo-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Release/Bingo) ==2734== by 0x400B69: main (in /home/holland/Code/cpp/Bingo-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Release/Bingo) ==2734== If you believe this happened as a result of a stack ==2734== overflow in your program's main thread (unlikely but ==2734== possible), you can try to increase the size of the ==2734== main thread stack using the --main-stacksize= flag. ==2734== The main thread stack size used in this run was 8388608. ==2734== ==2734== HEAP SUMMARY: ==2734== in use at exit: 86,091 bytes in 276 blocks ==2734== total heap usage: 2,819 allocs, 2,543 frees, 246,187 bytes allocated ==2734== ==2734== LEAK SUMMARY: ==2734== definitely lost: 0 bytes in 0 blocks ==2734== indirectly lost: 0 bytes in 0 blocks ==2734== possibly lost: 0 bytes in 0 blocks ==2734== still reachable: 86,091 bytes in 276 blocks ==2734== suppressed: 0 bytes in 0 blocks ==2734== Rerun with --leak-check=full to see details of leaked memory ==2734== ==2734== For counts of detected and suppressed errors, rerun with: -v ==2734== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)

BingoBoard分段故障 我一直在尝试用我在C++中创建的这个BIGO板来进行分割错误。Valgrind没有告诉我更多: ==2734== Memcheck, a memory error detector ==2734== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al. ==2734== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info ==2734== Command: ./Bingo ==2734== ==2734== Invalid read of size 1 ==2734== at 0x5D0A436: vfprintf (vfprintf.c:1620) ==2734== by 0x5DBF8ED: __printf_chk (printf_chk.c:37) ==2734== by 0x400FC0: generate(int, int) (in /home/holland/Code/cpp/Bingo-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Release/Bingo) ==2734== by 0x400B69: main (in /home/holland/Code/cpp/Bingo-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Release/Bingo) ==2734== Address 0x62 is not stack'd, malloc'd or (recently) free'd ==2734== ==2734== ==2734== Process terminating with default action of signal 11 (SIGSEGV) ==2734== Access not within mapped region at address 0x62 ==2734== at 0x5D0A436: vfprintf (vfprintf.c:1620) ==2734== by 0x5DBF8ED: __printf_chk (printf_chk.c:37) ==2734== by 0x400FC0: generate(int, int) (in /home/holland/Code/cpp/Bingo-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Release/Bingo) ==2734== by 0x400B69: main (in /home/holland/Code/cpp/Bingo-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Release/Bingo) ==2734== If you believe this happened as a result of a stack ==2734== overflow in your program's main thread (unlikely but ==2734== possible), you can try to increase the size of the ==2734== main thread stack using the --main-stacksize= flag. ==2734== The main thread stack size used in this run was 8388608. ==2734== ==2734== HEAP SUMMARY: ==2734== in use at exit: 86,091 bytes in 276 blocks ==2734== total heap usage: 2,819 allocs, 2,543 frees, 246,187 bytes allocated ==2734== ==2734== LEAK SUMMARY: ==2734== definitely lost: 0 bytes in 0 blocks ==2734== indirectly lost: 0 bytes in 0 blocks ==2734== possibly lost: 0 bytes in 0 blocks ==2734== still reachable: 86,091 bytes in 276 blocks ==2734== suppressed: 0 bytes in 0 blocks ==2734== Rerun with --leak-check=full to see details of leaked memory ==2734== ==2734== For counts of detected and suppressed errors, rerun with: -v ==2734== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4),c++,segmentation-fault,C++,Segmentation Fault,这是我的密码: #include <vector> #include <iostream> #include <algorithm> #include "board.h" #define MIN 0 #define MAX 15 using std::vector; using std::random_shuffle; using std::cout; using std::endl; void generate(int numRows, int num

这是我的密码:

#include <vector>
#include <iostream>
#include <algorithm>
#include "board.h"

#define MIN 0
#define MAX 15

using std::vector;
using std::random_shuffle;
using std::cout;
using std::endl;

void generate(int numRows, int numColumns) {

    std::vector<int> b;
    std::vector<int> i;
    std::vector<int> n;
    std::vector<int> g;
    std::vector<int> o;

    char * bingo = "bingo";

    for(int index = MIN; index <= 15; index++)
    {
        b.push_back(index);
        i.push_back(index + 15);
        n.push_back(index + 30);
        g.push_back(index + 45);
        o.push_back(index + 60);
    }

    std::random_shuffle(b.begin(), b.end());
    std::random_shuffle(i.begin(), i.end());
    std::random_shuffle(n.begin(), n.end());
    std::random_shuffle(g.begin(), g.end());
    std::random_shuffle(o.begin(), o.end());

    for (int i = 0; i <= 5; i++)
    {
        printf(" %s ", bingo[i]);
    }

    for (int j = 0; j <= 15; j++)
    {
        printf(" %d %d %d %d %d \n", b.back(), i.back(), n.back(), g.back(), o.back());
        //b.pop_back();
        //i.pop_back();
        //n.pop_back();
        //g.pop_back();
        //o.pop_back();
    }

    delete bingo;

}
#包括
#包括
#包括
#包括“board.h”
#定义最小值0
#定义最大值15
使用std::vector;
使用std::random_shuffle;
使用std::cout;
使用std::endl;
void生成(int numRows,int numColumns){
std::载体b;
std::向量i;
std::向量n;
std::向量g;
std::向量o;
char*bingo=“bingo”;
对于(int index=MIN;index而言,问题在于:

delete bingo;
其中,
bingo
不是指向通过使用
new
获得的内存,而是指向字符串文本

格式说明符或printf的参数也不正确:

printf(" %s ", bingo[i]);

%s
要求参数为
字符*
,但您的参数类型为整数。请将格式说明符更改为
%c
%d
或更改参数。

您可能指的是所有这些