简体   繁体   English

本地 Windows 调试器不断崩溃

[英]Local Windows Debugger Keeps crashing

I'm running into problems with my local debugger on visual studio while trying to learn C++, as soon as it gets to the end of the code it immediately closes and doesn't allow me to close it myself so I can't even see the final bit of output.我在尝试学习 C++ 时遇到了我在 Visual Studio 上的本地调试器的问题,一旦它到达代码的末尾,它就会立即关闭并且不允许我自己关闭它,所以我什至看不到最后一点输出。

As far as I know there are no errors in my code and I tried the getchar() so that I could enter a character before the debugger closing.据我所知,我的代码中没有错误,我尝试了getchar()以便我可以在调试器关闭之前输入一个字符。

Here's my code just incase there are errors but I don't think there are这是我的代码,以防出现错误,但我认为没有

    #include <iostream>

    using namespace std;

    int search(char* pchs, int size, char key) {
    int count = 0;

    for (int i = 0; i < size; i++) {
        if (pchs[i] == key) 
            count++;    
    }
    return count;
    }

    int main() {
    int size = 0;
    char key = 0;
    cout << "Please enter the size of the array" << endl;
    cin >> size;
    cout << "Please enter the key (a-z)" << endl;
    cin >> key;

    char* pchs = new char[size];

    if (pchs != NULL) {
        for (int i = 0; i < size; i++) {
            pchs[i] = 97 + rand() % 26;
            cout << pchs[i] << " ";
        }
        cout << endl;
        cout << "No. Occurences: " << search(pchs, size, key) << endl;
    }
    
    
    delete[] pchs;
    return 0;
}

Go to Tools -> Options and search for this option and disable it转到工具 -> 选项并搜索此选项并将其禁用调试停止时自动关闭控制台

You could try this method:你可以试试这个方法:

Right click on your project右键单击您的项目

Properties -> Configuration Properties -> Linker -> System -> Select Console (/SUBSYSTEM:CONSOLE)属性 -> 配置属性 -> 链接器 -> 系统 -> 选择控制台 (/SUBSYSTEM:CONSOLE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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