Fragensteller
#include <regex> in VS2012

Frage
-
Hallo,
in VS2008 ging das noch mit
#include <regex>
in VS2012 wird es nicht gefunden.
Muss ich das anders schreiben?
Wer weiß Rat?
Grüße Sandra
1 #include <iostream> 2 #include <fstream> 3 #include <regex> 4 5 using namespace tr1; 6 using namespace std; 7 8 int main() 9 { 10 std::string str = "Hello world"; 11 std::tr1::regex rx("ello"); 12 13 if(regex_match(str.begin(), str.end(), rx)) 14 { 15 cout<<"false"<<endl; 16 } 17 else 18 cout<<"true"<<endl; 19 return(0); 20 }
Alle Antworten
-
Hallo Sandra,
das include ist so korrekt.
Da regex Teil des verwendeten Standards im VS2012 Compiler ist, fällt die tr1 Erweiterung raus. Du schreibst leider nicht, was nicht gefunden wird, ich nehme daher einfach mal an, das es tr1 ist. Daher würde ich es mal so probieren:
1 #include <iostream> 2 3 #include <regex> 4 5 6 using namespace std; 7 8 int main() 9 { 10 string str = "Hello world"; 11 regex rx("ello"); 12 13 if(regex_match(str.begin(), str.end(), rx)) 14 { 15 cout<<"false"<<endl; 16 } 17 else 18 cout<<"true"<<endl; 19 return(0); 20 }
using namespace oder nicht, kläre das mal für Dich - einmal mit und einmal ohne ist verwirrend.
Gruß
- Florian
- Bearbeitet Florian Haupt Mittwoch, 27. Mai 2015 13:32 nicht relevantes include entfernt