iostream

Help with streams (.net)

I have a stream object, and I want to create and output xml using some kind of xml stream, based on data in my input stream. I haven't done much work with streams, so I am trying to learn how to do this as efficiently as possible. The idea is that I do not want to load the entire input stream in memory, then create the entire output st...

redirect std::cout to a custom writer

I want to use this snippet from Mr-Edd's iostreams article to print std::clog somewhere. #include <iostream> #include <iomanip> #include <string> #include <sstream> int main() { std::ostringstream oss; // Make clog use the buffer from oss std::streambuf *former_buff = std::clog.rdbuf(oss.rdbuf()); std::clog <<...

Custom manipulator for C++ iostream

Hi, I'd like to implement a custom manipulator for ostream to do some manipulation on the next item being inserted into the stream. For example, let's say I have a custom manipulator quote: std::ostringstream os; std::string name("Joe"); os << "SELECT * FROM customers WHERE name = " << quote << name; The manipulator quote will quote n...

How do I print a double value with full precision using cout?

So I've gotten the answer to my last question (I don't know why I didn't think of that). I was printing a double using cout that got rounded when I wasn't expecting it. How can I make cout print a double using full precision? Thanks ...

Java IO implementation of unix/linux "tail -f"

I'm wondering what techniques and/or library to use to implement the functionality of the linux command "tail -f ". I'm essentially looking for a drop in add-on/replacement for java.io.FileReader. Client code could look something like this: TailFileReader lft = new TailFileReader("application.log"); BufferedReader br = new BufferedRea...

Table layout using std::cout

How do I format my output in C++ streams to print fixed width left-aligned tables? Something like printf("%-14.3f%-14.3f\n", 12345.12345, 12345.12345); poducing 12345.123 12345.123 ...

how to output to console in C++/Windows

When using iostream in C++ on Linux, it displays the program output in the terminal, but in Windows, it just saves the output to a stdout.txt file. How can I, in Windows, make the output appear in the console? ...

iostream and large file support

I'm trying to find a definitive answer and can't, so I'm hoping someone might know. I'm developing a C++ app using GCC 4.x on Linux (32-bit OS). This app needs to be able to read files > 2GB in size. I would really like to use iostream stuff vs. FILE pointers, but I can't find if the large file #defines (_LARGEFILE_SOURCE, _LARGEFILE6...

Using boost::iostreams::tee_device?

Can someone help me? I am trying to do something like the following: #include <boost/iostreams/tee.hpp> #include <boost/iostreams/stream.hpp> #include <sstream> #include <cassert> namespace io = boost::iostreams; typedef io::stream<io::tee_device<std::stringstream, std::stringstream> > Tee; std::stringstream ss1, ss2; Tee my_split...

customize cout

How can I derive a class from cout so that, for example, writing to it new_cout << "message"; would be equivalent to cout << __FUNCTION__ << "message" << "end of message" << endl; ...

Using boost in WDK build environment for applications?

I am using the Windows Driver Kit (WinDDK 6001.18001) to build my userspace application rather than Visual Studio 2005. I am taking this approach because we also have to build driver components, so I'd prefer to have a single build environment to build everything. Microsoft itself uses this approach for several products. This was workin...

stringstream unsigned conversion broken?

Consider this program: #include <iostream> #include <string> #include <sstream> #include <cassert> int main() { std::istringstream stream( "-1" ); unsigned short n = 0; stream >> n; assert( stream.fail() && n == 0 ); std::cout << "can't convert -1 to unsigned short" << std::endl; return 0; } I tried this on gc...

What are the rules of the std::cin object in C++?

I am writing a small program for my personal use to practice learning C++ and for its functionality, an MLA citation generator (I'm writing a large paper with tens of citations). For lack of a better way to do it (I don't understand classes or using other .cpp files inside your main, so don't bother telling me, I'll work on that when I...

chaining c++ streams

I was thinking of "chaining" a couple of c++ iostreams toghether to filter input twice. I'm using gzstreams to read zlib compressed files and I was thinking of coding a stream that reads from a stream and performs encoding conversions. Perhaps by passing an opened stream as constructor parameter... How do you think this could be best acc...

Need Help parsing stream data from php socket server with perl.

I'm working on a project for my company that uses a socket server (php) to gather data from a remote device. How can I make this perl program run directly on the stream instead of first having the server write to a tmp file then running this script on that file then writing out a csv file for insertion into a database? I thought about ...

unix domain stream sockets sending more data then it should be

I have two simple programs set up that share data through a unix domain socket. One program reads data out of a Queue and sends it to the other application. Before it is sent each piece of data is front-appended by four bytes with the length, if it is less then four bytes the left over bytes are the '^' symbol. The client application t...

How does <iostream> work? (C++)

Just out of curiosity, how does iostream access the input-output system. (I have a bad habit of constantly reinventing the wheel, and I'm wondering if I can build a custom input-output system to the likes of iostream). ...

What is the reverse of cout.width? (C++)

I was trying std::cout.width(int) to see what it did, and it pushes the text right to fill a minimum width: TH becomes: TH to fill a minimum width of 10. I am wondering if A) there is a way to reverse this, have a number of spaces put AFTER the text to fill a minimum width, and B) is there a way to create a maximum width AN...

Using stringstream in place of string? - C++

I've been given a homework assignment to write a program in C++, but we're not allowed to use the string class. However, we are allowed to use the iostream library, including stringstream. I was thinking of using stringstream where I would have used string for building my classes, returning from functions, etc. Does this sound like a go...

$stdin compatibility with std::istream using swig, C++, and Ruby

I have a function in C++ that takes in an std::istream as the input: class Foo { Foo(std::istream &); } Using SWIG, I've bound it to Ruby, but Ruby's $stdin variable is fundamentally different from anything like the stream classes in C++, so I'm not sure how to either 1) expose the C++ class to Ruby in a way that I can use $stdin,...