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

本文介绍了 C++ TR1 技术报告中新增的重要特性,包括智能指针、正则表达式解析、新的容器类型如元组和无序集合等。通过示例展示了如何使用 TR1 中的正则表达式进行匹配。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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);
    } 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值