草庐IT

iter_entry_points

全部标签

c++ - Visual Studio regex_iterator 错误?

我在使用VisualStudio2013,我看到了一个我认为是错误的东西,我希望有人可以确认吗?stringfoo{"A\nB\rC\n\r"};vectorbar;for(sregex_iteratori(foo.cbegin(),foo.cend(),regex("(.*)[\n\r]{1,2}"));i!=sregex_iterator();++i){bar.push_back(i->operator[](1).str());}此代码在VisualStudio正则表达式库中命中调试断言:regex_iteratororphaned如果我在for循环之外定义regex没问题:str

c++ - 用 gcc 编译 std::regex_iterator

我可以使用g++-ctest.cpp-std=c++0x创建.o文件,但无法链接它,出现下一个错误:test.cpp:(.text+0xe5):undefinedreferenceto`std::regex_iterator>::regex_iterator(charconst*,charconst*,std::basic_regex>const&,std::bitset)'test.cpp:(.text+0xf1):undefinedreferenceto`std::regex_iterator>::regex_iterator()'代码:#include#include#inclu

c++ - 如何将分数纪元时间戳( double )转换为 std::chrono::time_point?

我有一个小数纪元时间戳,表示为double,我想将其转换为适当的std::chrono::time_point。纪元是自1/1/1970以来的常用UNIX纪元。我知道存在std::chrono::system_clock::from_time_t,但是time_t没有小数部分。使用C++11方法执行此操作的最佳方法是什么?这个问题与unixtimestamptoboost::posix_time::ptime有关,除了它要求的是C++11而不是它的Boost版本。 最佳答案 假设纪元与已知的时钟类型相同,您可以使用具有double表

c++ - std::filesystem::directory_iterator 链接器问题 (C++17)

这个问题在这里已经有了答案:LinkerrorsusingmembersinC++17(4个答案)关闭4年前。在尝试使用C++17标准中的std::filesystem::directory_iterator时,我的C++构建出现问题。代码如下:std::vectorIO::getDirectoryList(std::filesystem::path&dirPath){std::vectorfiles;for(auto&file:std::filesystem::directory_iterator(".")){files.push_back(file.path());}returnf

c++ - 特化 iterator_traits

我想专攻std::iterator_traits对于不具有通常的嵌套typedef(如value_type、difference_type等)的容器类模板的迭代器,我不应该修改其源代码。基本上我想做这样的事情:templatestructiterator_traits::iterator>{typedefTvalue_type;//etc.};除了这不起作用,因为编译器无法推断出T来自Container::iterator.有什么可行的方法可以达到同样的目的吗?例如:templateclassSomeContainerFromAThirdPartyLib{typedefTValueTy

c++ - 将 steady_clock::time_point 转换为 time_t

我正在使用steady_clock来保存一些消息的时间戳。出于调试目的,拥有日历(或类似的东西)很有用。对于其他时钟,有静态函数to_time_t,但在GCC(MinGW4.8.0)上,此函数不存在。现在我打印类似的东西:Timestamp:26735259098242对于时间戳,我需要一个steady_clock,所以我不能使用system_clock或其他。编辑之前的打印是从time_since_epoch().count()给出的 最佳答案 假设您需要内部计算的稳定行为,而不是显示,这里有一个函数可用于转换为time_t以供显

C++ 标准 : Unexpected const_iterator in multiset

我最近遇到了一个奇怪的问题,在遍历多重集时,我得到的是const_iterator而不是预期的iterator。结果证明这对MSVC来说不是问题,但g++给了我一个错误:error:invalidinitializationofreferenceoftype'myPtr&'fromexpressionoftype'constboost::shared_ptr'相关代码:typedefstd::multisetmyList;myList_mystuff;voidtick(floatdt){for(myList::iteratori=_mystuff.begin();i!=_mystuff

C++ 模板 std::vector::iterator 错误

在C++中,我试图获得std::vector::iterator对于我的模板类。但是,当我编译它时,出现错误:errorC2146:syntaxerror:missing';'beforeidentifier'iterator',errorC4430:missingtypespecifier-intassumed.Note:C++doesnotsupportdefault-int.我也收到警告:warningC4346:'std::vector::iterator':dependentnameisnotatype:#includetemplateclassv1{typedefstd::

c++ - 可以安全地存储 list::iterator 供以后使用吗?

假设我有一个列表,其中没有添加或删除新节点。但是,节点可能会被打乱。保存一个迭代器,指向列表中的一个节点,并在以后任意时间访问它是否安全?编辑(后续问题):list::splice()的文档说它从参数列表中删除元素。这是否意味着如果我调用splice,使用相同的列表作为函数的参数,现有的迭代器将失效? 最佳答案 是的。迭代器进入列表的标准受赠者不会失效,除非他们指向(比喻地说)的项目从列表中删除。从这个页面:http://www.sgi.com/tech/stl/List.htmlListshavetheimportantprope

c++ - 获取 POSIX 纪元作为 system_clock::time_point

我知道std::chrono::system_clock::time_point的默认值是时钟的纪元,但我在C++11标准中找不到任何规定system_clock的纪元与POSIX纪元(1970-01-01T00:00:00Z)相同。在Linux和Windows上假设是这种情况是否安全?或者使用std::chrono::system_clock::from_time_t(0)会更聪明吗? 最佳答案 标准离开std::chrono::system_clock::time_point的纪元未指定。std::chrono::system_