
Сообщение от
GoldenChild
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
| #include <iostream>
#include <locale>
#include <cstring>
using namespace std;
//1.Дана строка. Подсчитать количество содержащихся в ней цифр.
int countDigits(char *str) {
int k = 0;
int i = 0;
while (str[i] != '\0') {
if (isdigit(str[i])) k++;
i++;
}
return k;
}
int main() {
std::locale::global(std::locale(""));
int i;
char s[100];
cout<<"Введите 1-5 (выбора задания) "<<endl;
cin>>i;
switch(i) {
case 1: { cout<<"Введите строку желательно с цифрами "<<endl;
cin.get();
cin.getline(s, 100);
cout << s << endl;
cout<<"Количество цифр в строке = "<<countDigits(s)<<endl;
break;
}
case 2:
case 3:
case 4:
case 5:
;}
system("pause");
return 0;
} |
|
Спасибо,но казалось что работало и без cin.get();
Вот старый код,все работало....:
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| #include "stringlesson.h"
#include <iostream>
#include <locale>
#include <string.h>
using namespace std;
int main() {
std::locale::global(std::locale(""));
cout<<"1-ое задание :"<<endl;
cout<<"Введите строку "<<endl;
char s[100];
char s2[100];char s3[100];char s4[100];
cin.getline(s,100);
cout<<"Первая латинская гласная буква под номером = "<<FindFirstGlasn(s)<<endl;
cout<<"2-ое задание :"<<endl;
cout<<"Введите две строки "<<endl;
cin.getline(s2,100);
cin.getline(s3,100);
cout<<"Количество вхождений второй строки в первую = "<<KolVhogdS2VS1(s2,s3)<<endl;
cout<<"3-е задание :"<<endl;
cout<<"Введите строку с хотя бы одним пробелом "<<endl;
cin.getline(s4,100);
cout<<"Индекс последнего пробела = "<<FindIndLastSpace(s4)<<endl;
system("pause");
return 0;
} |
|