- #include<iostream>
- using namespace std;
- void reversit(char a[],int n)
- {
- int i;
- char t;
- for(i=0;i<(n+2)/2;i++)
- {
- t=a[i];
- a[i]=a[n-1-i];
- a[n-1-i]=t;
- }
- cout<<a<<endl;
- }
- int main()
- {
- const int Max=20;
- char a[Max];
- cin.get(a,Max); /*遇到空格继续输入*/
- int n; /*字符串长度*/
- cin>>n;
- reversit(a,n); /*此处a数组呈引用状态*/
- cout<<a; /*证明reversit函数采用的是应用a字符数组*/
- return 0;
- }
C++中类C方法逆置字符串并通过引用返回
最新推荐文章于 2023-08-21 19:50:58 发布