need information about regex library in C++ ..ASAP

Hello Fourm Memebrs,

As my first topic, i wish Hai to all the members and admin team.

issue.
i am not able to use regex in my C++ program and getting below issue.

##program##
#include<iostream>
#include<string.h>
#include<regex.h>
using namespace std;
int main()
{
string input;
regex integer("(\\+/-)?[[:digit:]]+");
while(true)
{
cout<<"Enter integer!"<<endl;
cin>>input;
if(regex_match(input,integer))
cout<<"integer"<<endl;
else
{
cout<<"INvalid input"<<endl;
}
}
}

##compile###
g++ scan_expr.cpp
scan_expr.cpp: In function ‘int main()’:
scan_expr.cpp:8:4: error: ‘regex’ was not declared in this scope
scan_expr.cpp:8:10: error: expected ‘;’ before ‘integer’
scan_expr.cpp:13:26: error: ‘integer’ was not declared in this scope
scan_expr.cpp:13:33: error: ‘regex_match’ was not declared in this scope


Please help to resolve this issue .my ubntu version is .
uname -a
Linux D-113032917 3.2.0-29-generic-pae #46-Ubuntu SMP Fri Jul 27 17:25:43 UTC 2012 i686 i686 i386 GNU/Linux


Thanks
Siva ranganath

If you want to use the standard C++ regex class and functions you should include the <regex> header.

<regex.h> is something else.
http://www.gnu.org/software/libc/manual/html_node/Regular-Expressions.html
Last edited on
Hello peter,
Thanks for immediate respond ,even i tried with regex i am getting same issue.

may i have to link any library to compile this program are include any header file to make it to work.

Thanks
Siva Ranganath
You need to compile as C++11 (or later).

g++ -std=c++11 scan_expr.cpp
Topic archived. No new replies allowed.