草庐IT

ostream_iterator

全部标签

c++ - boost::split 与 boost::iter_split 之间的区别

boost::split和boost::iter_split函数有什么区别? 最佳答案 boost::split将拆分后的字符串复制到SequenceSequenceT(例如std::vector)。boost::iter_split地点iterators(特别是迭代器范围)到SequenceSequenceT.这实际上意味着两件事:使用split将创建拷贝,因此原始字符串不会看到对返回的字符串容器的任何更改。此外,您无需担心迭代器失效。使用iter_split将返回一个迭代器范围的容器,因此,修改这些迭代器指向的内容也会修改原始字

c++ - std::ostream 第一次使用时未正确格式化 const char*

我一直在编写自定义std::streambuf作为日志系统的一部分。但是,我遇到了流输出的第一段格式不正确的问题。这是一个不使用任何自定义streambuf或ostream类的简化测试用例:#includeintmain(){std::streambuf*coutbuf=std::cout.rdbuf();std::ostream(coutbuf)使用g++编译:$g++--versiong++(Ubuntu4.4.1-4ubuntu8)4.4.1$g++-ofailreduced-case.cpp$./fail0x400c80:writingtocoutusingaseparateo

c++ - 命名空间 + 重载 std::ostream << 运算符

我正在尝试在我的C++应用程序中创建一个Vector3D类。对于我的整个程序,我使用的是命名空间。在这个命名空间中,我声明了我的Vector3D类和一个重载的运算符namespacespace{classVector3D{public:floatx,y,z;Vector3D(float_x=0,float_y=0,float_z=0);Vector3D(constVector3D&_vector);Vector3D&operator=(constVector3D&_vector);Vector3Doperator*(float_scalar);Vector3Doperator*(con

c++ - 为什么迭代器在 VS2010 中导致调试非常缓慢,即使 _HAS_ITERATOR_DEBUGGING、_SECURE_SCL、_SECURE_SCL_THROWS 设置为 0

我一直试图找出为什么在Debug模式下调试我们的程序需要这么长时间。在使用xperf查看堆栈的样子后,很明显我们在迭代器和STL容器上花费了大量时间。我在谷歌上搜索了一会儿,找到了选项_HAS_ITERATOR_DEBUGGING=0_SECURE_SCL=0_SECURE_SCL_THROWS=0我用#define在代码中设置所有这些#define_HAS_ITERATOR_DEBUGGING0#define_SECURE_SCL0#define_SECURE_SCL_THROWS0但这似乎没有用,所以我尝试使用visualstudio项目中的预处理器定义,但似乎仍然没有帮助。我已经

c++ - 尝试构建 muParser:错误:'std::basic_ostream 的显式实例化但没有可用的定义

我试图在mac上构建muParser,它一直有效,直到我将XCode升级到4.4并更新了gcc。现在我得到以下代码行生成我不明白的错误:mu::console()&std::operator&,conststd::basic_string&)[with_CharT=char,_Traits=std::char_traits,_Alloc=std::allocator]'butnodefinitionavailable../muparser/src/muParserBase.cpp:Ininstantiationof'std::basic_ostream&std::operator&,c

c++ - std::multiset::iterator = NULL 不再有效?

我有一些代码正在使用gcc4.7(从3.1)更新到C++11我有一个multiset定义为一个类的私有(private)成员:multisetobjects_;代码中有一段看起来像这样(p_q是一对多集迭代器,对那句讨厌的行感到抱歉,迫不及待地想用auto替换它,哈哈):voidTerrain::removeObject(Object*obj){pair::iterator,multiset::iterator>p_q;multiset::iteratorp,q;q=NULL;p_q=objects_.equal_range(obj);for(p=p_q.first;p!=p_q.se

C++ - 将 istream_iterator 与 wstringstream 一起使用

我正在尝试为我编写的程序添加Unicode支持。我的ASCII代码已编译并具有以下几行:std::stringstreamstream("abc");std::istream_iteratorit(stream);我将其转换为:std::wstringstreamstream(L"abc");std::istream_iteratorit(stream);我在istream_iterator构造函数中得到以下错误:errorC2664:'voidstd::vector::push_back(std::basic_string&&)':cannotconvertparameter1fro

c++ - 从 std::ostream_iterator 调用时未找到运算符 << 的重载?

这个程序//main.cpp#include#include#include#include#includetemplatestd::ostream&operator&pair){returnos";}intmain(){std::mapmap={{1,2},{2,3}};std::cout>(std::cout,""));//thisdoesn'twork}产生错误nomatchfor‘operator>::ostream_type{akastd::basic_ostream}’and‘conststd::pair’)我猜这是行不通的,因为我的重载在std::copy中不可用,但这是

c++ - 二进制表达式 ('ostream'(又名 'basic_ostream<char>')和 'ostream' 的无效操作数)

我正在努力cout但是,编译时出现“二进制表达式的无效操作数('ostream'(又名'basic_ostream')和'ostream')”错误。#includeusingnamespacestd;ostream&Print(ostream&out){out为什么这不起作用?我怎样才能解决这个问题?谢谢!! 最佳答案 您可能正在寻找的语法是std::cout.pointer函数被视为操纵器。内置operator将指针指向Print并用cout调用它.#includeusingnamespacestd;ostream&Print(o

c++ - 为什么 ranges::ostream_iterator 是默认可构造的?

这个问题遵循评论中的讨论here.在EricNiebler的ranges-v3library中(这有点成为C++20标准的一部分),ranges::ostream_iterator是default-constructible-没有ostream。怎么会?我认为后来有效构造的“虚拟”构造是C++中的反模式,我们正在逐渐摆脱这种缺陷。std::ostream迭代器canonlybeconstructedwithastream(目前-在C++20之前)。似乎我们可以用默认构造的range::ostream_iterator做任何事情...所以,这是怎么回事? 最佳