简体   繁体   English

c++ 在 ConsoleApplication1.exe 中的 0x7A45FF80 (ucrtbased.dll) 处抛出异常:0xC0000005:访问冲突读取位置 0x00000000

[英]c++ Exception thrown at 0x7A45FF80 (ucrtbased.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation reading location 0x00000000

i have an error when i run this code and I don't know what it is, I get an error in string in visual studio app运行此代码时出现错误,但我不知道它是什么,我在 Visual Studio 应用程序中收到字符串错误

the error " Exception thrown at 0x7A45FF80 (ucrtbased.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation reading location 0x00000000."错误“在 ConsoleApplication1.exe 中的 0x7A45FF80 (ucrtbased.dll) 处抛出异常:0xC0000005:访问冲突读取位置 0x00000000。”

#include <iostream>
using namespace std;
#include <string>

int main()
{
    float userinput01 = 0, userinput02 = 0;
    float avareg = 0;
    string option = 0;

    cout << "Welcome to Calculator app!\n" << "What is the desired operation?\n\nChoose the operation letter:\n" << endl;
    cout << "a- Additon\n" << "b- Subtraction\n" << "c- Multiplicstion\n" << "d- Division\n" << endl;

    if (option == "a") {
        cout << "Additon" << endl;
        cin >> userinput01 >> userinput02;
        avareg = userinput01 + userinput02;
        cout << userinput01 << "+" << userinput02 << "= " << avareg << endl;
    }
    else if (option == "b") {
        cout << "Subtraction" << endl;
        cin >> userinput01 >> userinput02;
        avareg = userinput01 - userinput02;
        cout << userinput01 << "-" << userinput02 << "= " << avareg << endl;
    }
    else if (option == "c") {
        cout << "Multiplicstion" << endl;
        cin >> userinput01 >> userinput02;
        avareg = userinput01 * userinput02;
        cout << userinput01 << "*" << userinput02 << "= " << avareg << endl;
    }
    else if (option == "d") {
        cout << "Division" << endl;
        cin >> userinput01 >> userinput02;
        avareg = userinput01 / userinput02;
        cout << userinput01 << "/" << userinput02 << "= " << avareg << endl;
    }
    else
        cout << "You did not choose a correct letter" << endl;

    return 0;
}

string option = 0; is the culprit and string option;是罪魁祸首和string option; is the fix.是修复。

The latter relies on the std::string default constructor.后者依赖于std::string默认构造函数。

The former will cause the constructor to a const char* to be called, with undefined results.前者将导致构造const char*调用const char* ,结果未定义。

暂无
暂无

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

相关问题 CandidateVotes.exe中0x50E6F1C0(ucrtbased.dll)抛出异常:0xC0000005:访问冲突读取位置0x00000000 - Exception thrown at 0x50E6F1C0 (ucrtbased.dll) in CandidateVotes.exe: 0xC0000005: Access violation reading location 0x00000000 为什么我在 ConsoleApplication1.exe 中的 0x00000000 处出现异常异常:0xC0000005:访问冲突执行位置 0x00000000 - Why do I get an Exception Exception thrown at 0x00000000 in ConsoleApplication1.exe: 0xC0000005: Access violation executing location 0x00000000 Metrics_Alpha.exe 中 0x78F90870 (ucrtbased.dll) 处的未处理异常:0xC0000005:访问冲突读取位置 0x00000000 - Unhandled exception at 0x78F90870 (ucrtbased.dll) in Metrics_Alpha.exe: 0xC0000005: Access violation reading location 0x00000000 在 ConsoleApplication5.exe 中的 0x0F640E09 (ucrtbased.dll) 处抛出异常:0xC0000005:访问冲突写入位置 0x014C3000? - Exception thrown at 0x0F640E09 (ucrtbased.dll) in ConsoleApplication5.exe: 0xC0000005: Access violation writing location 0x014C3000? MyString.exe中0x0FC9E559(ucrtbased.dll)的未处理异常:0xC0000005:访问冲突写入位置0x00000000 - Unhandled exception at 0x0FC9E559 (ucrtbased.dll) in MyString.exe: 0xC0000005: Access violation writing location 0x00000000 在 Class 12.exe 中的 0x7B37FF80 (ucrtbased.dll) 处引发异常:0xC0000005:访问冲突读取位置 0x00B64F88。 发生了 - Exception thrown at 0x7B37FF80 (ucrtbased.dll) in Class 12.exe: 0xC0000005: Access violation reading location 0x00B64F88. occurred 在 Project0_opengl.exe 中的 0x00000000 处抛出异常:0xC0000005:访问冲突执行位置 0x00000000 - Exception thrown at 0x00000000 in Project0_opengl.exe: 0xC0000005: Access violation executing location 0x00000000 在 CobwebDiagram.exe 中的 0x00000000 处引发异常:0xC0000005:访问冲突执行位置 0x00000000 - Exception thrown at 0x00000000 in CobwebDiagram.exe: 0xC0000005: Access violation executing location 0x00000000 在 Make Classes Iterable.exe 中的 0x7933F3BE (ucrtbased.dll) 处引发异常:0xC0000005:访问冲突读取位置 0xDDDDDDDD。 发生了 - Exception thrown at 0x7933F3BE (ucrtbased.dll) in Making Classes Iterable.exe: 0xC0000005: Access violation reading location 0xDDDDDDDD. occurred HW 5 Rational pt2.exe 中 0x5E10F1C0 (ucrtbased.dll) 处未处理的异常:0xC0000005:访问冲突读取位置 0xCCCCCCCC。 发生了 - Unhandled exception at 0x5E10F1C0 (ucrtbased.dll) in HW 5 Rational pt2.exe: 0xC0000005: Access violation reading location 0xCCCCCCCC. occurred
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM