视觉"如何修复错误 C4996:"_strupr":C++ 中的错误"
visual “How to fix error C4996: '_strupr': ’ error in c++”
我遵循指令将 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
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 错误:未在此范围内声明'reverse'