C++学习,第四十四课
已有 628 次阅读2014-8-27 09:52
|个人分类:作业
#include<iostream>
#include<string>
template<class T>
void swap(T &a, T &b)
{
T temp=a;
a = b;
b = temp;
}
int main()
{
int i1 = 100;
int i2 = 200;
std::cout << "交换前i1=" << i1 << ",i2=" << i2 << "\n\n";
swap(i1, i2);
std::cout << "交换后i1=" << i1 << ",i2=" << i2 << "\n\n";
std::string s1 = "小甲鱼";
std::string s2 = "小油鱼";
std::cout << "交换前s1=" <<s1 << ",s2=" << s2 << "\n\n";
swap(s1, s2);
std::cout << "交换后s1=" << s1 << ",s2=" <<s2 << "\n\n";
system("pause");
return 0;
}