Различия между `isdigit` и` std :: isdigit`C++

Программы на C++. Форум разработчиков
Anonymous
Различия между `isdigit` и` std :: isdigit`

Сообщение Anonymous »

Вот код, чтобы узнать, содержит ли строка только цифры: < /p>

Код: Выделить всё

#include 
#include 
#include 
#include 

int main() {
std::string s("123");
std::all_of(s.begin(), s.end(), std::isdigit);  //error!
}
Но код не компилируется, со следующими ошибками (произведенные с использованием clang ++ ):

Код: Выделить всё

error: no matching function for call to 'all_of'
note: candidate template ignored: couldn't infer template argument '_Predicate'
all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
Когда я заменяю std :: isdigit на iSdigit , код компилируется без ошибок.

Код: Выделить всё

#include 
#include 
#include 
#include 

int main() {
std::string s("123");
std::all_of(s.begin(), s.end(), isdigit);  //OK
}
Я попробовал вышеуказанное на Apple clang и linux g ++ и получил аналогичные ошибки.
Я знаю, что isdigit из заголовка C Ctype.h , и что std :: isdigit - обертка, определенная в заголовке C ++ cctype , так что По сути, они должны быть такими же. Итак, в чем разница между ISDigit и std :: isdigit ?

Подробнее здесь: https://stackoverflow.com/questions/758 ... stdisdigit

Вернуться в «C++»