草庐IT

ostream_iterator

全部标签

c++ - 在 C++17 中,为什么关联容器有一个 `erase` 成员函数(非 -`const` ) `iterator` ?

见,例如,http://en.cppreference.com/w/cpp/container/map/erase在C++03中有三个重载:voiderase(iteratorpos);voiderase(iteratorfirst,iteratorlast);size_typeerase(constkey_type&key);在C++11中,第一个和第二个重载被更改为采用const_iterator以便可以使用iterator或const_iterator调用它们>。第一个重载也得到了改进,它让迭代器在删除后将迭代器返回到元素:iteratorerase(const_iterator

C++ istream_iterator 不是 std 的成员

谁能告诉我为什么我在编译时写的下面这段代码一直在提示istream_iteratorisnotamemberofstd请你告诉我吗?谢谢大家#include#include#include#include#include#include#include//#includestructfield_reader:std::ctype{field_reader():std::ctype(get_table()){}staticstd::ctype_base::maskconst*get_table(){staticstd::vectorrc(table_size,std::ctype_bas

c++ - 从迭代器获取 const_iterator

这个问题在这里已经有了答案:关闭11年前.PossibleDuplicate:Obtainingconst_iteratorfromiterator我想写一个返回相应const_iterator的元函数来自iteratortemplatestructget_const_iterator{typedef???type;};get_const_iterator::type必须是constint*get_const_iterator::type必须是constint*get_const_iterator::type必须是constint*或constint*const,我不在乎get_con

c++ - 为什么 Clang std::ostream 会写入 std::istream 无法读取的 double 值?

我正在使用一个应用程序,它使用std::stringstream从文本文件中读取空格分隔的double矩阵。该应用程序使用的代码有点像:std::ifstreamfile{"data.dat"};constautoheader=read_header(file);constautonum_columns=header.size();std::stringline;while(std::getline(file,line)){std::istringstreamss{line};doubleval;std::size_ttokens{0};while(ss>>val){//dostuff

c++ - 错误 : cannot bind ‘std::basic_ostream<char>’ lvalue to ‘std::basic_ostream<char>&&’

我已经看过几个关于这个的问题,特别是Overloadingoperator&&’很有帮助。它让我知道我的问题是我正在做一些c++11无法从中推断出类型的事情。我认为我的问题的很大一部分是我正在使用的实例化类是模板化的,但最初是从指向非模板基类的指针中获得的。这是我从另一个关于如何将模板类对象放入STL容器的stackoverflow.com问题中建议的。我的课:classDbValueBase{protected:virtualvoid*null(){returnNULL;}//Neededtomakeclasspolymorphic};templateclassDbValue:pub

c++ - 为什么 std::count(_if) 返回 iterator::difference_type 而不是 size_t?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:WhydoestheC++standardalgorithm“count”returnaptrdiff_tinsteadofsize_t?标准C++中有std::count/std::count_if算法。templatetypenameiterator_traits::difference_typecount(InputIteratorfirst,InputIteratorlast,constT&value);templatetypenameiterator_traits::difference_typec

c++ - 检查迭代器的类型是否为 reverse_iterator

有没有办法检查作为arg传递给fnc的迭代器是否是reverse_iterator?我可以使用任何迭代器特征函数吗? 最佳答案 用偏特化来写很简单:#include#includetemplatestructis_reverse_iterator:std::false_type{};templatestructis_reverse_iterator>:std::true_type{};尽管如下所述,这并不能处理“反向-反向”迭代器的(恕我直言不太可能)情况。Bathsheba的答案中稍微不那么琐碎的版本正确处理了这种情况。

c++ - boost::filesystem::recursive_directory_iterator 带过滤器

我需要递归地从目录及其子目录中获取所有文件,但不包括几个目录。我知道他们的名字。是否可以使用boost::filesystem::recursive_directory_iterator? 最佳答案 是的,在遍历目录时,您可以测试排除列表中的名称并使用递归迭代器的no_push()成员来防止它进入这样的目录,例如:voidselective_search(constpath&search_here,conststd::string&exclude_this_directory){usingnamespaceboost::filesy

c++ - 为什么我不能用 T=vector<int> 实例化 operator<<(ostream&, vector<T>&)?

在思考C++iteratorquestion,我写了这个示例程序:#include#include#include#includetemplatestd::ostream&operator&v){os(os,","));returnosv(3);std::vector>vv(3,v);std::cout我用gcc编译这个程序并得到典型的100行错误。我相信相关的部分是:it.cc:19:instantiatedfromhere/usr/include/c++/4.4/bits/stream_iterator.h:191:error:nomatchfor‘operator((std::o

c++ - 为什么我不能从 iterator_traits 获取 value_type?

我正在这样做:constintarr[]={1,2,3,4,5,6,7,8,9,10,11,12,13};constautofoo=cbegin(arr);consttypenameiterator_traits::value_typebar=1;我会期待bar有类型int.但是我得到了一个错误:errorC2039:value_type:isnotamemberofstd::iterator_traits这是const的问题吗?我需要去掉那个吗? 最佳答案 这里的问题在于行constautofoo=cbegin(arr);cbeg