Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何检查向量或数组中两个不同或相同的元素是否相邻?_C++_C_Numbers - Fatal编程技术网

C++ 如何检查向量或数组中两个不同或相同的元素是否相邻?

C++ 如何检查向量或数组中两个不同或相同的元素是否相邻?,c++,c,numbers,C++,C,Numbers,我想知道如何检查两个数字或元素在向量中是否相邻 以下是我迄今为止编写并尝试的代码: // Check stack postfix, to see if operator needs to be pushed on for (int it = 0; it < postfixstack.size(); it++) { int count = 0; // keeps track of how many numbers

我想知道如何检查两个数字或元素在向量中是否相邻

以下是我迄今为止编写并尝试的代码:

// Check stack postfix, to see if operator needs to be pushed on
         for (int it = 0; it < postfixstack.size(); it++)
         {
             int count = 0; // keeps track of how many numbers

                              // If number, continue, else....do something?
             if (isdigit(it))
             {
                 count++;
                 continue;
             }

             else
                              // do something if element is not a number

         }
//检查堆栈后缀,查看是否需要推送运算符
for(int it=0;it

我在使用sstream标题时运气不错

你是说像
std::nexture\u-find
?nexture\u-find做什么?我对向量函数有点陌生。我只知道一些基本知识,比如push_back和cbeginasuming postfix stack.size()>0,你需要对它进行一次完整性检查+1
if(postfix stack[it]==postfix stack[it+1])
正确,我只是查找了相邻的_findon和@TheFloatingBrain Yes correct向量中已经有元素了。虽然不必是相同的数字,但可以是不同的数字。@user110182抱歉,我以为您想检查例如
vec[0]=2;vec[1]=2//