这个程序为什么不对!(求救!!!!!!!!
#include <iostream>
using namespace std;
int main()
{
void swap(int *p1, int *p2)
int *pointer_1,*pointer_2,a,b;
cin> > a> > b;
pointer_1=&a;
pointer_2=&b;
if(a <b) swap(pointer_1,pointer_2);
cout < < "max= " < <a < < "min= " < <b < <endl;
return 0;
}
void swap(int *p1,int *p2)
{int temp;
temp=*p1;
*p1=*p2;
*p2=temp;
}
运行结果是:
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
D:\C++垃圾箱\Cpp1.cpp(6) : warning C4518: 'int ' : storage-class or type specifier(s) unexpected here; ignored
D:\C++垃圾箱\Cpp1.cpp(6) : error C2143: syntax error : missing '; ' before '* '
D:\C++垃圾箱\Cpp1.cpp(6) : error C2065: 'pointer_1 ' : undeclared identifier
D:\C++垃圾箱\Cpp1.cpp(6) : error C2100: illegal indirection
D:\C++垃圾箱\Cpp1.cpp(6) : error C2065: 'pointer_2 ' : undeclared identifier
D:\C++垃圾箱\Cpp1.cpp(6) : error C2100: illegal indirection
D:\C++垃圾箱\Cpp1.cpp(6) : error C2065: 'a ' : undeclared identifier
D:\C++垃圾箱\Cpp1.cpp(6) : error C2065: 'b ' : undeclared identifier
D:\C++垃圾箱\Cpp1.cpp(8) : error C2440: '= ' : cannot convert from 'int * ' to 'int '
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
D:\C++垃圾箱\Cpp1.cpp(9) : error C2440: '= ' : cannot convert from 'int * ' to 'int '
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.
Cpp1.obj - 9 error(s), 1 warning(s)
[解决办法]
include <iostream>
using namespace std;
void swap(int *p1, int *p2);
int main()
{
int *pointer_1,*pointer_2,a,b;
cin> > a> > b;
pointer_1=&a;
pointer_2=&b;
if(a <b) swap(pointer_1,pointer_2);
cout < < "max= " < <a < < "min= " < <b < <endl;
return 0;
}
void swap(int *p1,int *p2)
{int temp;
temp=*p1;
*p1=*p2;
*p2=temp;
}