Advertisement
JewishCat

stroki

May 23rd, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. // vlad.ryad.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <cstdlib>
  6. #include <iostream>
  7. #include <stdio.h>
  8. #include <string>
  9. using namespace std;
  10.  
  11. /*
  12. *
  13. */
  14.  
  15. bool str_start(string str, char *sim, char *sl);
  16. int main() {
  17.     setlocale(LC_ALL,"RUSSIAN");
  18.     string line;
  19.     char *buf = new char;
  20.     char *sl = new char[1];
  21.     cout << "Введите строчку:" << endl;
  22.     getline(cin, line);
  23.     cout << "Введите набор символов" << endl;
  24.     cin >> buf;
  25.  
  26.     if (str_start(line, buf, sl)) {
  27.         cout << "Строчка начинает с:" << buf << endl;
  28.     }
  29.     else {
  30.         cout << "Строчка не начинается массивом символов" << endl;
  31.     }
  32.     system("pause");
  33.     return 0;
  34. }
  35.  
  36. bool str_start(string str, char *sim, char *sl) {
  37.     bool flag = 0;
  38.     int x = 0;
  39.     while (str[x] != '\0') {
  40.         if (str[x] != ' ') {
  41.             for (int i = 0; i<sizeof(sim); i++) {
  42.                 if (str[x] != sim[i]) {
  43.                     break;
  44.                     flag = 0;
  45.                 }
  46.                 else {
  47.                     flag = 1;
  48.                     continue;
  49.                 }
  50.             }
  51.         }
  52.         x++;
  53.     }
  54.     return flag;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement