草庐IT

iostreams

全部标签

c++ - python sys.stdout 和 C++ iostreams::cout

我假设sys.stdout将引用与在同一进程中运行的iostreams::cout相同的物理流,但事实似乎并非如此。以下代码使用名为“write”的python包装器调用C++函数,该函数写入cout:fromcStringIOimportStringIOimportsysorig_stdout=sys.stdoutsys.stdout=stringout=StringIO()write("cout")#wrappedC++functionthatwritestocoutprint"-"*40print"stdout"sys.stdout=orig_stdoutprintstringo

c++ - 为什么我们需要在编译期间包含 C 或 CPP 声明文件而不是像 iostream 这样的默认库?

如果C或CPP程序需要使用我们自己的带有声明的头文件和带有定义的cpp文件进行编译,我们需要在编译命令中包含带有定义的cpp文件(参见thisanswer)。但是,当我们写#include,我们不包括iostream.cpp在类似g++main.cppiostream.cpp-omain的编译语句中.如果我们编写自定义声明文件,例如hello.hpp带有类声明和hello.cpp有了定义,我们需要使用g++main.cpphello.cpp-omain编译它包括hello.hpp之后在标题中main.cpp文件。这是为什么?编辑:我们是否可以为我们的自定义头文件和cpp文件模仿标准模板

c++ - `#include <iostream>` 和 `-std=c++0x` 坏了

如果我指定-std=c++0x到g++,那么我不能#include.我收到以下错误消息(mingw下的g++4.4.0):Infileincludedfromc:\qt\2010.05\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/postypes.h:42,fromc:\qt\2010.05\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/iosfwd:42,fromc:\qt\2010.05\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c

c++ - 在 Ctrl+Z (EOF) 后恢复从 iostream::cin 读取? ("ignore"不起作用)

为什么当我们只为内部循环提供ctrl+z时,下面程序中的外部循环会终止?#includeintmain(){strings1,s2;while(cin>>s1){cout>s2)cout 最佳答案 按Ctrl+z(在Windows上)关闭标准输入流。一旦关闭,它就会保持关闭状态。内循环完成后,它不会神奇地重新打开。没有理由会这样。 关于c++-在Ctrl+Z(EOF)后恢复从iostream::cin读取?("ignore"不起作用),我们在StackOverflow上找到一个类似的问题

c++ - 使用 boost::archive 和 boost::iostreams 来压缩数据

我想为一个可以选择性地压缩数据的类编写一个序列化函数。我想使用boost::iostreams中提供的压缩工具。有谁知道如何做到这一点?structX{X(){}templatevoidserialize(Archive&ar,constunsignedintversion){ar&compression;if(compression==0){ar&data;}elseif(compression==1){//useboost::iostreamcompression//facilitiestoserializedata}}intcompression;std::vectordata;

c++ - Eclipse CDT 中的虚假错误:boost::iostreams

我在EclipseCDT(JunoSR1)中有以下代码:#include#include#include#include#includeintmain(){usingnamespacestd;namespaceio=boost::iostreams;ifstreamfile("data.gz",ios_base::in|ios_base::binary);io::filtering_streambufin;in.push(io::gzip_decompressor());//errorherein.push(file);//andhere}g++4.7.2代码没有问题。然而,Eclip

C++解压缩一个gzip字节数组

这是完整的情况:我正在为.tmx文件开发map阅读器,来自平铺。大多数情况下,图block都保存在base64字符串中,其中包含一个由gzip压缩的字节数组。现在我可以读取压缩字节数组,但我不知道如何解压缩它。我阅读了一些关于zlib和boost的文档,但两者都是关于文件流的,而且非常复杂......我是数据压缩领域的新手,所以如果有人知道某种解决方案或一些有用的文档,我将不胜感激。 最佳答案 #include#include#include#include#includeintmain(){usingnamespacestd;if

c++ - 静态顺序初始化失败,iostream 和 C++11

根据C++11规范:Theresultsofincludinginatranslationunitshallbeasifdefinedaninstanceofios_base::Initwithstaticstorageduration.Similarly,theentireprogramshallbehaveasiftherewereatleastoneinstanceofios_base::Initwithstaticstorageduration这意味着如果我的代码看起来像这样://A.cpp#includeusingnamespacestd;unsignedlongfoo(){

c++ - 为什么整数溢出会导致 C++ iostream 出错?

好的,所以我对C++iostream有一些感觉很奇怪的问题,但它可能是定义的行为,考虑到MSVC++和G++都会发生这种情况。假设我有这个程序:#includeusingnamespacestd;intmain(){inta;cin>>a;cout>a;cout如果我通过给第一个cin一个大于int的最大限制的值来故意溢出,所有对cin.operator>>()的进一步调用将由于某种原因立即返回,并且a被设置为某个值。该值似乎未定义。为什么,这种行为记录在哪里?有没有办法确定是否发生了这种溢出?另外,这个类似的程序似乎可以按我的预期运行。如果我溢出该值,它会为a提供一些值,并继续进行,

c++ - Boost Gzip 过滤器 : compile failes

我正在尝试从BoostGzip过滤器页面编译示例:#include#include#include#include#includeintmain(){usingnamespacestd;ifstreamfile("hello.gz",ios_base::in|ios_base::binary);filtering_streambufin;in.push(gzip_decompressor());in.push(file);boost::iostreams::copy(in,cout);}遗憾的是我的g++返回错误:gzlib.cpp:Infunction‘intmain()’:gzli