.


:




:

































 

 

 

 





string.h. , , , , , ( ) .

1. int strlen (const char* s); - s. , . , - . ,

cout << strlen("Hello!"); // 6 char *str = "one";cout << strlen(str); // 3

2. char *strcpy(char *s1, const char *s2); - s2 s1. s1. s1 , , . ,

char str[25]; // 25 char *ps = new char [25]; /* 25 */ strcpy(str, "ABCDE"); // str "ABCDE" cout << str; // str . ABCDE strcpy(ps, "QWERTY"); // ps "QWERTY" cout << ps; // ps . QWERTY delete[] ps; //

, , , , ! , , ps = "QWERTY" . , , "QWERTY", ( Q) ps. , ps, ps.

3. int *strcmp(const char *s1, const char *s2); - s1 s2 ( ASCII-). 0, s1 s2 , , s1 s2, , s1 s2. , , , ASCII- (.. "g" "ff"). ,

cout << strcmp("compare", "string"); /* -1, "compare" "string" */ cout << strcmp("abcde", "abc"); // 1, "abcde" "abc" cout << strcmp("one", "one"); /* 0, */

4. char *strcat(char *s1, const char *s2); - s2 s1. s2 - s1. s1. s1 (strlen(s1)+strlen(s2)+1). ,

char st1[25] = "";cout << strcat(st1, " !"); // !

5. char *strncpy(char *s1, const char *s2, int n); - n s2 s1. s1.

6. char *strncmp(char *s1, const char *s2, int n); - n s1 s2. 0, , 0 , 0, s1 , s2.

7. char *strncat(char *s1, const char *s2, int n); - n s2 s1. s1.

8. char *strchr(const char *s, int c); - s c. c s. , NULL. ,

char str[20] = "ABCDEXYZ";cout << strchr(str, 'X'); // XYZ

char str[20] = "ABCDEXYZ";if (strchr(str, 'q') == NULL) cout << " !";

9. char *strstr(const char *s1, const char *s2); - s1 s2. s2 s1. , NULL. ,

char str[20] = "ABCDEXYZ";char *ps = strstr(str, "DEX");if (ps!= NULL) cout << ps; else cout << " !"; // DEXYZ

10. char *strlwr(char *s); - (.. ). ,

char str[30] = "ABCDE_123_ijk_XYZ";cout << strlwr(str); // abcde_123_ijk_xyz

11. char *strupr(char *s); - (.. ).

12. char *strset(char *s, int ch); - s ch. ,

char str[30] = "ABCDE";cout << strset(str, 'x'); // xxxxx

13. char *strnset(char *s, int ch, int n); - n s ch.

14. char *strrev(char *s); - ( , ..). ,

char str[30] = "12345";cout << strrev(str); // 54321

. string.h .

2.4 ++.

1. , x.

. , . , , , , , - 1, . ( -) . : .

#include iostreamusing namespace std;void main() { char str[100]; // // cout << "Vvedite stroky: "; cin >> str; // , int Kol = 0; /* -, */ // -, // - 1. int i = 0; while(str[i]!= '\0') { if (str[i] == 'x') Kol++; i++; } // cout << "Kolichestvo x ravno " << Kol;}

2. , , , S s.

. : , S s. S ( s) , . S s.

:

(.. ),

S s,

.

. . i, i . : :

A b s D e f0 1 2 3 4 5 ------

, , 2 . , 1 , .. :

A b D e f0 1 2 3 4

.

++.

#include iostreamusing namespace std;void main(){ const int n=10; // char A[n]; // // , cout << "Do enter any string but no more then "<< n-1 << "symbols"<<endl; cin >> A; // int i=0; while(A[i]!='\0') // if (A[i]=='S'||A[i]=='s') // {/* , ...*/ for (int j=i;A[j]!='\0';j++) A[j]=A[j+1]; } else i++; /*, , */ cout << endl << A << endl; // */ }

. , , (.. )? ?

4. .

#include iostream #include <string.h> // ! using namespace std;   void main() { char s1[]=""; cout << strlen(s1); }

5. strcat .

  #include "iostream" #include <string.h> using namespace std;   void main() { char s1[55]="Ekaterina"; char s2[55]="Alikseevna"; cout << strcat(s1, s2); }

6. .

. , "" "", , . , , "Jones" "Smith", J S. ?

, ; , . (: , , , )

#include "iostream" #include <string.h> using namespace std;   void main() { char s1[5]; // cout<<"Enter a string (max 4 symbols):"; cin>>s1; // char s2[5]; // cout<<"Enter a string (max 4 symbols):"; cin>>s2; //   // ? if(strcmp(s1, s2) > 0) cout << "String s1:\t" << s1 << "\n\t > \n" << "String s2:\t" << s2 << endl; else if(strcmp(s1, s2) == 0) cout << "String s1:\t" << s1 << "\n\t=\n" << "String s2:\t" << s2 << endl; else cout << "String s1:\t" << s1 << "\n\t < \n" << "String s2:\t" << s2 << endl; }




:


: 2015-05-07; !; : 1070 |


:

:

, - , ; , - .
==> ...

1281 - | 1315 -


© 2015-2024 lektsii.org - -

: 0.017 .