如何在visual c ++ 2010中使用C ++ TR1库?
答案 0 :(得分:5)
VS2010内置了一些C ++ 0x功能。 TR1的某些功能(如数学函数)不包含在TR1的Visual C ++实现中。
boost has an implementation of TR1,您可以通过downloading boost获取。
要从VS2010禁用C ++ 0x / TR1标头并使用boost实现,请在VS2010项目的项目设置中定义_HAS_CPP0X=0
。
答案 1 :(得分:4)
如果你想使用与VS10一起打包的TR1的实现,只需简单地#include你需要的头文件并立即运行。并非所有TR1都包含在TR1的VS10实现中。您可以在工厂提供的实现here中找到TR1(和C ++ 0x作为一个整体)的哪些部分的列表,这里是一个简单的示例,说明如何在VS10中使用正则表达式MSDN sample page:
// std_tr1__regex__regex_search.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
int main()
{
const char *first = "abcd";
const char *last = first + strlen(first);
std::cmatch mr;
std::regex rx("abc");
std::regex_constants::match_flag_type fl =
std::regex_constants::match_default;
std::cout << "search(f, f+1, \"abc\") == " << std::boolalpha
<< regex_search(first, first + 1, rx, fl) << std::endl;
std::cout << "search(f, l, \"abc\") == " << std::boolalpha
<< regex_search(first, last, mr, rx) << std::endl;
std::cout << " matched: \"" << mr.str() << "\"" << std::endl;
std::cout << "search(\"a\", \"abc\") == " << std::boolalpha
<< regex_search("a", rx) << std::endl;
std::cout << "search(\"xabcd\", \"abc\") == " << std::boolalpha
<< regex_search("xabcd", mr, rx) << std::endl;
std::cout << " matched: \"" << mr.str() << "\"" << std::endl;
std::cout << "search(string, \"abc\") == " << std::boolalpha
<< regex_search(std::string("a"), rx) << std::endl;
std::string str("abcabc");
std::match_results<std::string::const_iterator> mr2;
std::cout << "search(string, \"abc\") == " << std::boolalpha
<< regex_search(str, mr2, rx) << std::endl;
std::cout << " matched: \"" << mr2.str() << "\"" << std::endl;
return (0);
}
答案 2 :(得分:2)
与GCC不同,VC2010中的TR1标头不会隔离在TR1/
目录中。我知道这不是因为使用VC而是因为有人告诉我GCC的实现在这种方式上是不寻常的。
N1836 1.3 / 4:
建议使用默认情况下未定义的宏保护标准标头中的其他声明,或者将所有扩展标头(包括具有非标准声明的标准标头的新标头和并行版本)放置在单独的目录,不属于默认搜索路径。
因此,您可能还需要添加#define
。不幸的是,他们没有将此标准化!