Determine if a string is numeric: Difference between revisions

added C translation to C++
(→‎BQN: add)
(added C translation to C++)
Line 1,531:
 
<syntaxhighlight lang="c">#include <ctype.h>
#include <stdbool.h>
#include <stdlib.h>
 
intbool isNumeric (const char * s) {
{
if (s == NULL || *s == '\0' || isspace(*s)) {
return 0false;
char * p;}
strtodchar (s, &*p);
strtod(s, &p);
return *p == '\0';
}</syntaxhighlight>
Line 1,572 ⟶ 1,574:
 
=={{header|C++}}==
{{trans|C}}<syntaxhighlight lang="cpp">#include <cctype>
#include <cstdlib>
 
bool isNumeric(const char *s) {
if (s == nullptr || *s == '\0' || std::isspace(*s)) {
return false;
}
char *p;
std::strtod(s, &p);
return *p == '\0';
}</syntaxhighlight>
 
Using stringstream:
<syntaxhighlight lang="cpp">#include <sstream> // for istringstream
3

edits