Visual C++ 2008 Feature Pack发布,可以在VS中直接使用tr1了

This feature pack also includes an implementation of TR1. Portions of TR1 are scheduled for adoption in the upcoming C++0x standard as the first major addition to the ISO 2003 standard C++ library. Our implementation includes a number of important features such as:
  • Smart pointers
  • Regular expression parsing
  • New containers (tuple, array, unordered set, etc)
  • Sophisticated random number generators
  • Polymorphic function wrappers
  • Type traits
  • And more! 

#include <regex>
#include <iostream>

typedef std::tr1::basic_regex<char> Myregex;
typedef std::tr1::match_results<const char *> Mymr;
int main()
    {
    const char *first = "abc";
    const char *last = first + strlen(first);
    Mymr mr;
    Myregex rx("abc");
    std::tr1::regex_constants::match_flag_type fl =
        std::tr1::regex_constants::match_default;

    std::cout << "match(f, f+1, /"abc/") == " << std::boolalpha
        << regex_match(first, first + 1, rx, fl) << std::endl;

    std::cout << "match(f, l, /"abc/") == " << std::boolalpha
        << regex_match(first, last, mr, rx) << std::endl;
    std::cout << "  matched: /"" << mr.str() << "/"" << std::endl;

    std::cout << "match(/"a/", /"abc/") == " << std::boolalpha
        << regex_match("a", rx) << std::endl;

    std::cout << "match(/"abc/", /"abc/") == " << std::boolalpha
        << regex_match("abc", mr, rx) << std::endl;
    std::cout << "  matched: /"" << mr.str() << "/"" << std::endl;

    std::cout << "match(string, /"abc/") == " << std::boolalpha
        << regex_match(std::string("a"), rx) << std::endl;

    std::string str("abc");
    std::tr1::match_results<std::string::const_iterator> mr2;
    std::cout << "match(string, /"abc/") == " << std::boolalpha
        << regex_match(str, mr2, rx) << std::endl;
    std::cout << "  matched: /"" << mr2.str() << "/"" << std::endl;

    return (0);
    } 

 

你可能感兴趣的:(C++,String,regex,Constants,containers,Pointers)