草庐IT

istream_iterators

全部标签

c++ - 使用 boost::iterator_facade 的优点和缺点是什么?

是的——标题几乎概括了它。我有很多实现迭代器概念的类型,我想知道是否值得引入这个boostheader而不是手动实现。到目前为止:优势明确说明不太可能有错误 最佳答案 如果维护您自己的迭代器类型成为一种负担,那么请改用boost。它们经过详细说明和测试,不太可能出现错误。 关于c++-使用boost::iterator_facade的优点和缺点是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/

C++ : How to write a const_iterator?

我用迭代器编写了自己的容器模板。如何实现const_iterator?templateclassmy_container{private:...public:my_container():...{}~my_container(){}classiterator:publicstd::iterator{public:... 最佳答案 唯一的区别应该是,当您取消引用const迭代器时,您得到的是const引用,而不是对容器中对象的引用。 关于C++:Howtowriteaconst_itera

c++ - 使用 istream::seekg 是不是太贵了?

在c++中,使用istream::seekg操作的开销有多大?编辑:我可以通过搜索文件和读取字节来逃脱多少?频率与偏移幅度的关系如何?我正在解析一个大文件(4GB),我想知道是否有必要尝试合并我的一些seekg调用。我认为文件位置差异的大小会产生一定影响——比如如果你在内存中寻找超过一页,它会影响性能——但小的寻找是无关紧要的。这是正确的吗? 最佳答案 这个问题在很大程度上取决于您的操作系统和磁盘子系统。显然,查找本身将花费基本上为零的时间,因为它只是更新一个偏移量。实际上读取会从磁盘中提取一些数据......但是有多少数据取决于很

c++11:使用 const_iterator 删除

我相信从C++11开始,erase大多数容器的功能(例如std::vector)接受const_iterator作为参数:iteratorerase(const_iteratorposition);我的编译器(GCC4.8和Clang3.2,都使用GCClibstdc++)仍然不允许我使用这样的函数,即使在使用--std=c++11编译时也是如此。.是编译器/libstdc++错误,还是我做错了什么?这是示例代码:#includeintmain(){std::vectorv;v.push_back(1);v.push_back(2);v.push_back(3);std::vector

c++ - libc++ 和 libstdc++ 之间的 istream eof 差异

以下(玩具)程序在链接到libstdc++和libc++时返回不同的东西。这是libc++中的错误还是我不明白istreameof()是如何工作的?我已经尝试在linux和macosx上使用g++运行它,在macosx上使用clang,有和没有-std=c++0x。我的印象是eof()在尝试读取(通过get()或其他方式)实际失败之前不会返回true。这是libstdc++的行为方式,而不是libc++的行为方式。#include#includeintmain(){std::stringstreams;s 最佳答案 编辑:这是由于旧

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