如何在此代码中更改x和y的值?x和y的交换值
当我试图通过x=y, y=x;
它将它更改为相同的数字。
我该怎么做?
我该如何做3个值,如(x
y
z
)?
#include <iostream>
using namespace std;
int main()
{
int x=4;
int y=6;
cout<<x<<y;
return 0;
}
我以前试过这个代码,但它不能按我想要的方式工作。
#include <iostream>
using namespace std;
int main()
{
int x=4;
int y=6;
x=y,y=x;
cout<<x<<y;
return 0;
}
这个词是“交换”。你会得到相当不错的谷歌结果。 – LogicStuff
C++标准库附带了许多不错的[algorithm](http://en.cppreference.com/w/cpp/algorithm)和[utility](http://en.cppreference.com/w/cpp/utility)功能。 –