草庐IT

istream-iterator

全部标签

c++ - 如何将 BOOST_FOREACH 与仅支持 const_iterator 的容器一起使用?

我有这个容器:class/*final*/Row{public:typedefFieldIteratorconst_iterator;typedefFieldIteratoriterator;FieldIteratorbegin()const;FieldIteratorend()const;FieldIteratorbegin();FieldIteratorend();...};鉴于此,以下代码可以正常编译:BOOST_FOREACH(Fieldfield,row){}但是,Row类不应该有可变迭代器,所以我更改了Row类,删除了可变访问:class/*final*/Row{publi

c++ - 重载 >> istream_iterator 对

这个问题在这里已经有了答案:Dependentnameresolution&namespacestd/StandardLibrary(1个回答)关闭7年前。我正在尝试构建对上的ifstream_iterator。我的代码如下:typedefpairT;istream&operator>>(istream&stream,T&in){stream>>in.first>>in.second;returnstream;}intmain(intargc,char**argv){ifstreaminfile("dummy2");istream_iteratoriit(infile);istream

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++ - 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++ - 以 std::istream&& 为参数是否合理?

我遇到过这样做的代码:SomeObjectparse(std::istream&&input){....input参数是右值引用,这通常意味着该函数旨在获取参数的所有权。这不是这里发生的事情。parse函数将完全消耗输入流,它需要一个右值引用,因为调用代码将放弃istream的所有权,因此这是一个信号输入流将不可用。我认为这没问题,因为parse函数实际上并没有四处移动对象,因此不存在切出子类型的危险。从parse的角度来看,这基本上表现为一个正常的引用,只是对调用函数有一种可编译的注释,您必须放弃流的所有权。这段代码真的安全吗?还是有一些被忽视的微妙之处导致了这种危险?

c++ - C++ 的 istream::eof() 的不一致是规范中的错误还是实现中的错误?

以下程序演示了std::istream(特别是在我的测试代码中,std::istringstream)设置eof()的方式不一致。#include#includeintmain(intargc,constchar*argv[]){//EXHIBITA:{//Anemptystreamdoesn'trecognizethatit'sempty...std::istringstreamstream("");assert(!stream.eof());//(NotyetEOF.Maybeshouldbe.)//...untilIreadfromit:constintc=stream.get(

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++ - 是否可以在 C++11 中手动设置 istream 失败位

我做了这门课:classobject{//data...public:friendstd::istream&operator>>(std::istream&in,object&o){charc,d;in>>c>>d;if(c==d){/*setthefailbitsomehow*/in.putback(d);in.putback(c);}elseo.set_data(c,d);returnin;}};我正在查看文档(不太好),但找不到设置失败位的正确方法。我关心的原因是我希望能够while(std::cin>>obj)/*dostuff*/;就像一个人可以用int做的那样。但是,如果我