iostream

Do C++ formatting libraries generally fall back to *sprintf for numeric formatting?

核能气质少年 提交于 2019-12-07 22:07:07
问题 I am wondering whether "all" C++ formatting libraries eventually fall back to a *sprintf function to format numbers. I am asking this because: Looking at the iostreams library that comes with Visual C++, I can see that numbers input into a stream will eventuall be formatted with sprintf_s . Boost.Format just uses the available iostreams library as far as I can tell. FastFormat eventually uses vsprintf to format a number. So, are there iostreams implementations that do not use *sprintf and do

Intercept all writes to a std::streambuf

蹲街弑〆低调 提交于 2019-12-07 19:16:05
问题 I am making a class that inherits std::streambuf (to asynchronously write to a UART). I need to be able to tell in my class whenever the std::ostream that holds the streambuf writes characters to it (so I can enable the "write ready" interrupt and actually write the data). I was under the impression that I just needed to override xsputn() , but that does not seem to get called. I could: Keep the interrupt enabled (inefficient) Use std::endl to call std::streambuf::sync() (blocking, ugly)

increase buffer for cout

爷,独闯天下 提交于 2019-12-07 17:42:25
问题 Citing Does setbuf() affect cout? I want to increase the buffer size to improve the performance of cout (it is usually redirected to disk) Can I do: std::cout.rdbuf()->pubsetbuf(some_buffer, buffer_size); And also ios::sync_with_stdio(false); Does this make sense? EDIT: Also I am using multiple threads, so I was hoping to reduce the need for synchronization. 回答1: I would first check on the number of flushes that will make any larger buffer size irrelevant. Especially look, if you have a lot

初级C++4IO流

本秂侑毒 提交于 2019-12-07 16:23:35
输入输出流 输入输出的含义: 从操作系统的角度看,每一个与主机相连的输入输出设备都被看作一个文件。 程序的输入:从文件传送给程序。 程序的输出:从程序传送给文件。 分类: 1、标准I/O 键盘输入 显示器输出 2、文件I/O 外存输入 外存输出 3、字符串I/O 内存输入 内存输出 C语言回顾 int i= 1; //假定占2字节 printf("%d",i); //正确输出 printf("%d",f); //f为float型,只输出f变量的前两个字节 printf("%d","C++"); //输出字符串的起始地址 scanf("%d",&i);//将内容写入变量i scanf("%d",i);//将内容写入内存地址为i的地方 C++的输入输出中,编译系统对数据类型进行严格的检查。 C++的I/O操作是类型安全的。 type safe —————————————————————————————— 流stream 输入输出流是指由若干字节组成的字节序列,这些字节中的数据按顺序从一个对象传送到另一对象。 流表示了信息从源到目的端的流动。 实际上,在内存中为每一个数据流开辟一个内存缓冲区,用来存放流中的数据。 流是与缓冲区相对应的。 缓冲区中的数据就是流。 输入输出流被定义为类 I/O库中的类被称为流类 stream class 用流类定义的对象被称为流对象 ios istream

How to use a compressor Boost::Iostreams filter as a sink in Boost::Log

て烟熏妆下的殇ゞ 提交于 2019-12-07 16:13:54
问题 I'm trying to compress log files created using the Boost Log library instantaneously by utilizing boost::iostreams::gzip_compressor . So when I call BOOST_LOG() , output gets compressed on-the-fly. Here's what I tried so far: #include <fstream> #include <iostream> #include <boost/iostreams/filtering_stream.hpp> #include <boost/iostreams/filtering_streambuf.hpp> #include <boost/iostreams/stream.hpp> #include <boost/iostreams/filter/gzip.hpp> #include <boost/smart_ptr/shared_ptr.hpp> #include

std::cin.readsome always reading 0 bytes

跟風遠走 提交于 2019-12-07 15:29:37
问题 I did a simple test with C++ code and using the helper tool pv (pipe viewer). The code is: #include <iostream> #include <array> int main() { std::array<char,4096> buffer; while( true ) { std::cin.readsome(buffer.data(),4096); } } I execute with: pv /dev/urandom | ./a.out Through pv , I notice that readsome never reads anything. What am I missing? 回答1: Please see cppreference, especially under "Notes". The behavior of this function is highly implementation-specific. For example, when used with

Save file from byte array on servermap path

a 夏天 提交于 2019-12-07 13:05:44
I Want to save a PDF file from a byte array and want to save that file on my server map path location. Below is my code snippet. It's giving no errors nor saving the file. You are welcome to correct my syntax if it is wrong or help me by referring other code snippets. byte[] data = (byte[])listDataset.Tables[0].Rows[0][0]; System.IO.FileStream file = System.IO.File.Create(Server.MapPath(".\\TmpImages\\"+hfFileName+".pdf ")); file.Write(data, 0, data.Length); file.Close(); It could be a permissions issue... The account ASP.net runs under has to have write privileges to the target directory.

fatal error C1083: Cannot open include file: 'iostream': No such file or directory

五迷三道 提交于 2019-12-07 09:21:05
问题 I've reinstalled Visual Studio 2010 Professional several times to try to get it to work. I had to uninstall Visual Studio 2012 Professional because it wasn't compiling something we did in class. I completely uninstalled everything including SQL Server.. I went to VC/include and the iostream header file is not there. #include <iostream> int main () { cout << "hello"; system ("PAUSE"); return 0; } This is all I'm trying to do because nothing else is working. It's really driving me crazy because

条款2:尽量用而不用 [effective C++ 学习笔记]

﹥>﹥吖頭↗ 提交于 2019-12-07 08:18:32
简而言之,<stdio.h>这个属于C语言的头文件,在使用的时候,需要很明确所要操作变量的类型,这无疑会增加很多风险,因为一开始的时候,可能定义的这个属于int型,但是后期的需求变更或者异常的数据传入时,这个数据可能会变成double型,那么还需要在所有对这个变量的打印,输出,使用的地方做全面的排查,看这些文章这些都是显而易见的,只是对文章后面的话比较感兴趣.因为这是在平时不太注意的地方。 “ 第一,有些iostream的操作实现起来比相应的C stream效率要低” ,因为iostream 其实是对operator<< 和operator>>重载,按理来说应该大多数都应该会比C stream效率低,还没有比 C stream高的实例,这部分继续关注 “ 第二,在标准化的过程中,iostream库在底层做了很多修改,所以对那些要求最大可移植性的应用程序来说,会发现不同的厂商遵循标准的程度也不同“ 这主要是想说iostream在移植方面可能会存在很多风险,因为不同的平台有不同的标准,其实C Stream 对于研发者来说,确实使用起来不是很方面,对于现在 C++,C#,java其实都有很多的iostream流处理操作,对于开发者来说,可以很方便的使用,可以减少代码的开发量和复杂程度,但是所有的事情发展都有好的一面和不好的一面。在享有方便快捷的开发时,所要付出的代价就是跨平台移植

How to derive from C++ std::basic_ostream and make the << operator virtual?

£可爱£侵袭症+ 提交于 2019-12-07 06:18:22
问题 I am writing a class that has various messages output. I want to make this class general and platform independent, so I am thinking of passing a basic_ostream reference to it and it can dump all the messages into the stream. By doing this, if the class is used in a console program, I can pass std::cout to it and display in console window. Or I could pass a derived ostream to it and redirect the message to some UI components, e.g. ListBox? The only problem is the data inserter operator << is