C++ 是否可以在C+中使用整数保留+;?

C++ 是否可以在C+中使用整数保留+;?,c++,C++,我想反转整数的位置,如下所示: x=2 y=10 结果:2 | 4 | 6 | 8 | 10 反转后:10 | 8 | 6 | 4 | 2 我的问题是。。。我可以使用以下代码: reverse(x.begin(), x.end()); 请在下面检查我的语法: int x; int y; cout<<"Input your numbers = "; cin>>x; cout<<"Last Result ="; cin>>y; while (x

我想反转整数的位置,如下所示:

x=2
y=10
结果:2 | 4 | 6 | 8 | 10
反转后:10 | 8 | 6 | 4 | 2

我的问题是。。。我可以使用以下代码:

reverse(x.begin(),
x.end());
请在下面检查我的语法:

int x;
int y;


cout<<"Input your numbers = ";
cin>>x;
cout<<"Last Result =";
cin>>y;

while (x < y){ 
cout<<x<<"|"; 
x+=2;

reverse(x.begin(),
x.end());
cout << x << endl;
intx;
int-y;
coutx;
库蒂;
而(x
int x;
int y;


cout<<"Input your numbers = ";
cin>>x;
cout<<"Last Result = ";
cin>>y;

vector<int> numbers;

while (x <= y)
{ 
    cout<<x<<"|";
    numbers.push_back(x);
    x+=2;
}

reverse(numbers.begin(), numbers.end());
cout << endl;

for (int num : numbers)
{
    cout << num << "|";
}
intx;
int-y;
coutx;
库蒂;
向量数;

虽然(x可以使用向量,但以下是如何操作:

vector<int> vex; 

while( x < y) {
       cout << x << "|";
       x += 2 
       vex.push_back(x);
}

auto r_begin = vex.rbegin();
auto r_end = vex.rend();

while ( r_begin != r_end ) {
      cout << r_begin << "|";
      ++r_begin; // here incrementing means going to previous element
 }
向量凸;
while(x第一步:找出你得到的错误类型。因为你没有保存任何数字,所以没有什么可以逆转的。
reverse
是一个容器操作。如果你想从y开始打印x和y之间的数字,每次迭代跳两个数字,不要在第一个循环中污染x(使用另一个变量),然后从y运行到x(使用
-=2
)谢谢:)我希望这能解决我的问题:)#HellGrammar:VThank:)但是等等,我不能得到它,这是什么意思==>push_back(x);?它只意味着取x值并将其放在vex的后面。当你使用push_back(args)时它将继续在调用push_back(args)的容器后面追加args。