Skip to content

Instantly share code, notes, and snippets.

@goyalankit
Created November 8, 2013 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goyalankit/7364976 to your computer and use it in GitHub Desktop.
Save goyalankit/7364976 to your computer and use it in GitHub Desktop.
Method to check if given string is a number or not.
#include<iostream>
#include<regex>
#include<string>
int main(void){
std::string num = "-23.43";
if (std::regex_match (num, std::regex("^[+|-]{0,1}(\\d)*\\.?\\d+$") ))
std::cout << "it's a number" << std::endl;
else
std::cout << "not a number" << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment