所以我有一个数组,看起来是这样的:
std::string Operators[4] = {
"+",
"-",
"*",
"/"
};我还有一根绳子,看上去像这样
std::string Equation = "1+1";我试图让代码检查来自数组的加号是否在等式字符串中。这和在字符串中找到子字符串没有什么不同吗?任何帮助都是非常感谢的。
发布于 2022-04-09 01:10:07
使用find_first_of
std::string Equation = "1+1";
std::size_t found = Equation.find_first_of("+-/*");如果找到char,“found”将是偏移量(在本例中为1)。如果未找到,则“found”将等于std::string::npos
看见
要知道找到哪个操作员,请执行
char op = Equation[found];https://stackoverflow.com/questions/71804110
复制相似问题