#include <iostream>#include<cstring>using namespacestd;voidBackaround (Char*s,Char*p);intMainintargcChar*argv[]) { Chars[ -],p[ -]; inti; intJ; intLen; Cin.getline (s), -);//used to determine input data//cout<<s;Len = strlen (s);//This loop is used to separate sentence words . for(i=0, j=0; i<len;i++){ if(s[i]!=' ') p[j++]=S[i]; Else{p[j]=' /'; Backaround (p,p+j-1);cout<<p<<" "; j=0;} } P[j]=' /'; Backaround (P,p+j-1); cout<<p; return 0;}voidBackaround (Char*s,Char*p) { if(s>=p)return ; *s^=*p;//data transposition using XOR operation*p^=*s; *s^=*p; Backaround (S+1, P-1);}
The code has a reference: do not remember which is the reference, here is the introduction of Cin.getline () function use method, but also update, cin.getline (s,sizeof, ' a '); Enter a string, ending with a, but excluding a.
Put the following code:
1#include <iostream>2#include <cstring>3 using namespacestd;4 voidBackaround (Char*s,Char*p);5 intMainintargcChar*argv[])6 {7 Chars[ -];//p[500];8 //int i;9 //Int J;Ten intLen; OneCin.getline (s), -,'.');//used to determine input data Acout<<s<<Endl; -Len =strlen (s); -cout << Len <<Endl; the}
You can see that the string output has no "." At the same time strlen calculation string does not put the end of the string to enter the count, the space calculation,
However, if the carriage return is used as a newline character, it will be counted as a char.
For now, Strlen calculates the return key used as a newline character, but does not calculate the return of the end of the string.
C + + Use Cin.getline Use example note point 2: Character count