在c++使用swap函数需要怎么样的头文件

我用swap函数编译是为什么出现“error C2065: 'swap' : undeclared identifier”

使用swap函数需要#include<iostream>头文件

示例:

#include<iostream>

//usingnamespacestd;

intmain(intargc,char*argv[])

{

inta=5;

intb=8;

std::swap(a,b);

std::cout<<a<<""<<b<<std::endl;

return0;

}

扩展资料

C++头文件algorith的使用

#include<iostream>

#include<algorithm>

usingnamespacestd;

boolcmp(constinta,constintb)

{

returna>b;

}

intmain()

{

intdata[5];

for(inti=0;i<5;i++)

cin>>data[i];

sort(data,data+5,cmp);

return0;

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-12-05
#include <algorithm>
第2个回答  2011-12-16
没加头文件
第3个回答  2011-12-05

确实在algorithm里边。
#include "stdafx.h"
#include <iostream>
#include <algorithm>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int a,b,c;
cin>>a>>b>>c;
if(a>b) swap (a,b);
if(b>c) swap (b,c);
if(a>b) swap (a,b);
int m=b;
cout<<b<<endl;

return 0;
}本回答被提问者采纳
第4个回答  2011-12-05
你没有定义这个函数

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网