-1

I have a string:

string str1= "hello"; 
string str2="hel"; 

And I am doing this to see if str1 has str2 in it:

regex e = str2+"*"
 bool x=regex_match(str1,e); 
cout<<x; 

I am getting this : error: conversion from 'std::__cxx11::basic_string' to non-scalar type 'std::__cxx11::regex {aka std::__cxx11::basic_regex}' requested regex e = str2+"";

How to use the variable in my regex. Can someone please tell me where am I going wrong? TIA.

hydra123
  • 337
  • 5
  • 14

1 Answers1

5

Look at reference about constructor of regex

template <class ST, class SA>
explicit basic_regex ( const basic_string<charT,ST,SA>& str, flag_type flags = 
 ECMAScript );

constructor is explicit so you should write

    regex e(str2+"*");

not

    regex e = str2+"*";
rafix07
  • 20,001
  • 3
  • 20
  • 33