Programming_Course1_Session2/17/Lab17/Lab17.cpp
2023-03-08 23:03:44 +01:00

32 lines
662 B
C++

#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
int findFirstDigitIndex(string str) {
for (int i = 0; i < str.length(); i++) {
if (isdigit(str[i])) {
return i;
}
}
return -1;
}
int main() {
SetConsoleOutputCP(CP_UTF8);
string inputStr;
cout << "Введіть строку: ";
cin >> inputStr;
int index = findFirstDigitIndex(inputStr);
if (index >= 0) {
cout << "Індекс першої цифри в цій строчці: " << index << endl;
}
else {
cout << "No digit was found in the input string." << endl;
}
return 0;
}