c++字符串逆序输出

@桑秒618:c++ 输入一个字符串,将其中的字符逆序输出 -
胡版19756937517…… sizeof是这个变量占的内存大小,要得到string类型的字符串的长度可以用成员函数length()或者size() 其实还可以一种简单的逆序方法, string str1("1234567890"); string str2(str1.rbegin(), str1.rend());

@桑秒618:C++ 字符串中的字符逆序输出 -
胡版19756937517…… #include <iostream> using namespace std; void main() { char s[20]; int len;//len没初始化 cout<<"请输入一个字符串:"; cin>>s; cout<<endl; cout<<"逆序输出为:"; for(int i=0;s[i]!='10';i++) len=i; //for(i=len-1;i>=o;i--)//注意0和o for(i=len-1;i>=0;i--) { cout<<s[i]; } cout<<endl; }

@桑秒618:用C++编写:输入一个字符串,将其逆序后输出.... -
胡版19756937517…… #include <iostream>#include <cstring> using namespace std; int main() { char s[255]; int l; cin >> s; l = strlen(s); char * p, *q, t; p = s; q = s + l - 1; while (p < q) { t = *p; *(p++) = *q; *(q--) = t;} cout << s; } 测试通过

@桑秒618:c++中输入一个字符串.使其倒序输出 -
胡版19756937517…… #include<stdio.h>#include<string.h> void fun(char *a) //其实你的n没有用.可以去掉 { int i,j; char t; //字符 j=strlen(a); for(i=0;i<j/2;i++)//一半就行 { t=a[i];a[i]=a[j-i-1];a[j-i-1]=t; //这里需要{}; }//是从j-1开始; // return a[i]; 不用返回 } int main() { char a[100]; scanf("%s",a);// printf("%s",fun(a,100));//是输出 fun(a); printf("%s",a); }

@桑秒618:c++编写函数实现一个字符串的逆序.在主函数中输入字符串,调用函数将字符串逆序,而后输出. -
胡版19756937517…… #include using namespace std; void rev(char s[]) {char *p,*q,c; for(p=s;*p;p++); for(q=s,--p;q<p;) {c=*p;*p--=*q;*q++=c;} } int main() { char s[100]; cin.getline(s,100); rev(s); cout<<s<<endl; return 0; }

@桑秒618:C++输入一个字符串,将其逆序存放并输出 -
胡版19756937517…… 利用C++标准库中对zhidaostring的支持,回程序可答以这样写:#include <iostream>#include <string> using namespace std; int main() { string input; cin>>input; string result = input; int len = input.length(); for(int i= len; i>=0; i--) { result[len-i]=input[i-1]; } cout<<result<<endl; return 0; }

@桑秒618:C++中输入一个字符串并将其逆序输出,怎么编程? -
胡版19756937517…… #include <string.h>#include <iostream> using namespace std; int main(int argc,char** argv) { char text[512]={0}; cout<<"请输入一字符串:"<<endl; cin>>text; int len=strlen(text); char* p=text+len; cout<<"逆序输出为:"<<endl; while ((p--)!=text) { cout<<*p; } cout<<endl; return 0; }

@桑秒618:C++编程:输入一个字符串 把其中的字符按逆序输出 如输入LIGHT 输出THGIL. (1)用字 -
胡版19756937517…… #include #include #include #include using namespace std; int main() { char ch[100]; string str; printf("请输入一个字符串:\n"); cin >> ch; str = ch; //字符数组方法 printf("字符数组方法\n"); for (int i = strlen(ch)-1; i >= 0; i--) printf("%c",...

@桑秒618:C++中输入一个字符串并将其逆序输出,怎么编程? -
胡版19756937517…… #include using namespace std; int main(int argc,char** argv){ char text[512]={0}; cout<<"请输入一字符...

@桑秒618:用C++编写一个程序,输入一串字符,然后让其逆序输出.如输入“Visual C++ Program"输出”margorP ++C lausiV",注意中间带有空格.
胡版19756937517…… #include<stdio.h>void main(){ int i,n; i=n=0; char *str1; gets(str1); //输入字符串 puts(str1); //输出字符串 while(*(str1+i)!='\0') { n++; //计算字符长度 i++; } for(i=n-1;i<0;i--) putchar(*(str+i)); //逆序输出}

相关推荐

相关链接:
  • c++字符串
  • c++字符串的定义
  • c++字符类型
  • c++字典
  • c++字符串转化为数字
  • c++字符数组
  • c++字符串的输入
  • c++字典序排序
  • c++字符串的长度怎么计算
  • c++字符三角形
  • 本文由网友投稿,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
    若有什么问题请联系我们
    2024© 客安网