视觉"如何修复错误 C4996:"_strupr":C++ 中的错误"

visual “How to fix error C4996: '_strupr': ’ error in c++”

本文关键字:错误 C++ strupr C4996 何修复 视觉      更新时间:2023-10-16

我遵循指令将 strupr更改为 _strupr和给予其他erro,然后我更改为 _strupr_s,但它说

参数类型是char *

任何人可以提供帮助吗?

// interpreter.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <cctype>
#include "Interpreter.h"
using namespace std;
double Statement::findValue(char *id)   //Return the  value
{
IdNode tmp(id);
list<IdNode>::iterator i = find(idList.begin(), idList.end(), tmp);
if (i != idList.end())
    return i->value;
else
    issueError("unknown variable");
return 0;
}
void Statement::processNode(char *id, double e) //Update the value or add it to the list
{
IdNode tmp(id, e);
list<IdNode>::iterator i = find(idList.begin(), idList.end(), tmp);
if (i != idList.end())
    i->value = e;
else
    idList.push_front(tmp);
 }
 void Statement::readId(char *id)  //Read input into an array
{
int i = 0;
if (isspace(ch))
    cin >> ch;
if (isalpha(ch)){ //If it is a letter, save the subsequent numbers or letters.
    while (isalnum(ch)){
        id[i++] = ch;
        cin.get(ch);
    }
    id[i] = '';
}
else
    issueError("Identifier expected");
}
double Statement::factor()  //Factor processing
{
double var, minus = 1.0;
static char id[200];
cin >> ch;
while (ch == '+' || ch == '-'){ //Is the symbol before the number
    if (ch == '-')   //Determine positive and negative
        minus *= -1.0;
    cin >> ch;
}
if (isdigit(ch) || ch == '.'){   //number
    cin.putback(ch);
    cin >> var >> ch; //save vaule
}
else if (ch == '('){ //Equal to the left parenthesis to handle the expression inside the parentheses
    var = expression(); //Recursively processing expressions in parentheses
    if (ch == ')')   //The right parenthesis continues to process ch
        cin >> ch;
    else
        issueError("right paren left out");
}
else{
    readId(id);
    if (isspace(ch))
        cin >> ch;
    var = findValue(id);
}
return minus * var;
}
double Statement::term()
{
double f = factor();
while (true){
    switch (ch){
    case '*':
        f *= factor();
        break;
    case '/':
        f /= factor();
        break;
    default:
        return f;
    }
  }
 }
double Statement::expression()
{
double t = term();
while (true){
    switch (ch){
    case '+':
        t += term();
        break;
    case '-':
        t -= term();
        break;
    default:
        return t;
    }
}
}
void Statement::getStatement()
{
char id[20];
char command[20];
double e;
cout << "enter a statement: ";
cin >> ch;
readId(id);
_strupr_s(strcpy(command, id));
if (strcmp(command, "STATUS") == 0)
    cout << *this;
if (strcmp(command, "PRINT") == 0){
    readId(id);
    cout << id << " = " << findValue(id) << endl;
}
else if (strcmp(command, "END") == 0)
    exit(0);
else{
    if (isspace(ch))
        cin >> ch;
    if (ch == '='){
        e = expression();
        if (ch != ';')
            issueError("there are some extras in the statement. ");
        else
            processNode(id, e);
    }
    else
        issueError("'=' is missing");
}
}
ostream &operator<<(ostream &out, const Statement &s)
{
list<IdNode>::const_iterator i = s.idList.begin();
for (; i != s.idList.end(); i++)
    out << *i;
out << endl;
return out;
}
ostream &operator<<(ostream &out, const IdNode &r)
{
out << r.id << " = " << r.value << endl;
return out;
}
int main()
{
Statement statement;
cout << "the program processes statements  of the following format:n"
    << "t<id> = <expr>;ntprint <id>ntstatusntendnn";
while (true)
    statement.getStatement();
return 0;
}

// TODO: reference additional headers your program requires here

根据文档,_strupr_s定义为:

errno_t _strupr_s(
   char *str,
   size_t numberOfElements
);

您的代码称该函数为:

_strupr_s(strcpy(command, id));

您要离开第二个参数:size_t numberOfElements