简体   繁体   中英

Debugging C++ program on Visual Studio 2013

when i debug this simple program it gives me segmentation fault, no errors on code.

anyone knows?

returns error chkstk.asm not found

#include "stdafx.h"
#include <stdlib.h>
#include <iostream>
#include <string>
#include <iostream>
using namespace std;


class saude{

    int dl, MAX, al;


public:
    struct pessoa_t{
        string nome;
        string Morada;
        int idade;
        int tel;
        string perfil; //se for "e" == enfermeiro; "m" == médico; "d" == doente
    };

    struct pessoa_t t[100];

    void queue(){ //mete as posicoes a nulo
        dl = -1; //fim da fila
        al = -1; //topo da fila
    }

    void del(){
        pessoa_t tmp;
        if (dl == -1){
            cout << "FILA VAZIA";
        }else{
            for (int j = 0; j <= al; j++){
                if ((j + 1) <= al){ //envia os valores para trás
                    tmp = t[j + 1];
                    t[j] = tmp;
                }else{ //se chegarmos ao fim da fila ele simplesmente remove o valor
                    al--;
                    if (al == -1) dl = -1;
                    else dl = 0;
                }
            }
        }
    }
    void add(pessoa_t item){
        if (dl == -1 && al == -1){
            dl++;
            al++;
        }else{
            al++;
            if (al == MAX){
                cout << "FILA CHEIA\n";
                al--;
                return;
            }
        }
        t[al] = item;
    }

    void display() {
        if (dl != -1) {
            for (int iter = 0; iter <= al; iter++)
                cout << t[iter].nome << " ";
        }
        else cout << "VAZIA";
    }
};



int _tmain(int argc, _TCHAR* argv[])
{
    saude a;

    saude::pessoa_t pessoas[2];
    pessoas[0].nome = "Ricardo";
    pessoas[0].Morada = "Penafiel";
    pessoas[0].perfil = "e";
    pessoas[0].tel = 91832782;

    pessoas[1].nome = "João";
    pessoas[1].Morada = "Penafiel";
    pessoas[1].perfil = "m";
    pessoas[1].tel = 94832744;


    cout << "Fila antes de insercao: ";
    a.display();
    cout << endl << endl;

    for (int iter = 0; iter < 5; iter++){
        a.add(pessoas[iter]);
        cout << "Nro adicao: " << (iter + 1) << " : ";
        a.display();
        cout << endl;
    }
    cout << endl;
    cout << "Fila depois de adicao: ";
    a.display();
    cout << endl << endl;
    for (int iter = 0; iter < 5; iter++){
        a.del();
        cout << "Nro remocao: " << (iter + 1) << " : ";
        a.display();
        cout << endl;
    }
    system:"pause";
    return 0;

}

You have an array with 2 elements, but you're trying to access 5 elements.

Adding something that's not actually a saude::pessoa_t , but random stuff lying around in memory, to a saude will break very badly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM