#include <iostream>
#include <stdlib.h>
#include <string>
#include<string.h>
#include <stdio.h>
using namespace std;
void OpCode()
{
string mnemonic;
int hex;
char *op;
cout << "Entre mnemonic : ";
cin >> mnemonic;
char *str1 = strdup(mnemonic.c_str());
if(strcmp(str1, "ADD") == 0)
{
hex = 24;
itoa(hex,op,16);
cout << op;
cout << "\nEqual";
}
else
cout << "\nFalse";
}
int main()
{
OpCode();
return 0;
}
它一直运行到我使用 op 变量的部分,我尝试在 main 函数中复制和粘贴它完美地工作,为什么它不能在 OpCode 函数中工作?!提前致谢