iostream

why don't STL ifstream and ofstream classes take std::string as filenames?

This is a complaint about STL. Why do they take filename arguments as (char *) and not as std::string? This seems to make no sense. There are two other questions on this topic: How to open unicode filenames with STL Windows Codepage interactions with C++ The issue is that I have a lot of code that looks like this: std::ofst...

Can I use Boost's format library to replace iostream?

Hi, I don't like to use <iostream> in C++ Library. I prefer to use something that is similar to "printf" and "scanf" in <stdio.h>. Can I use Boost's format library to replace <iostream> in all my C++ program ? ...

how to write any custom data type to file using ifstream?

as question says, i want to write custom data type data of a class maybe to a file using ifstream in c++. Need help. ...

Who architected / designed C++'s IOStreams, and would it still be considered well-designed by today's standards?

First off, it may seem that I'm asking for subjective opinions, but that's not what I'm after. I'd love to hear some well-grounded arguments on this topic. In the hope of getting some insight into how a modern streams / serialization framework ought to be designed, I recently got myself a copy of the book Standard C++ IOStreams and Lo...

C++ IO with Hard Drive

I was wondering if there was any kind of portable (Mac&Windows) method of reading and writing to the hard drive which goes beyond iostream.h, in particular features like getting a list of all the files in a folder, moving files around, ect. I was hoping that there would be something like SDL around, but so far I havn't been able to find...

im counting the number of characters in a file but i want to count the number of words that are less than 5 and 6 or greater.

i want to do this: reads the words in the file one at a time. (Use a string to do this) Counts three things: how many single-character words are in the file, how many short (2 to 5 characters) words are in the file, and how many long (6 or more characters) words are in the file. HELP HERE im not sure on how about reading file into a st...

HTTP server that handles requests through IO devices?

This question can probably only be answered for Unix-like systems that follow the "everything is a file" idiom. Would it be hard to create a web server that mounts local devices for handling http traffic? It would enable a program to read raw http requests from /dev/httpin (for example) and write the responses to /dev/httpout. I think t...

Using boost::asio::async_read with stdin?

hi poeple.. short question: I have a realtime-simulation which is running as a backround process and is connected with pipes to the calling pogramm. I want to send commands to that process using stdin to get certain information from it via stdout. Now because it is a real-time process, it has to be a non blocking input. Is boost::asio::a...

C++ STL: How to write wrappers for cout, cerr, cin and endl?

I do not like using namespace std, but I am also tired of having to type std:: in front of every cout, cin, cerr and endl. So, I thought of giving them shorter new names like this: // STLWrapper.h #include <iostream> #include <string> extern std::ostream& Cout; extern std::ostream& Cerr; extern std::istream& Cin; extern std::string& ...

Why do I get this strange output behavior?

I have the following program test.cc: #include <iostream> unsigned char bogus1[] = { // Changing # of periods (0x2e) changes output after periods. 0x2e, 0x2e, 0x2e, 0x2e }; unsigned int bogus2 = 1816; // Changing this value changes output. int main() { std::clog << bogus1; } I build it with: g++ -g -c -o test.o test.cc; g++ -s...

c++ manipulator question

i have a class: template<class T> class matrix { private: int COLS,ROWS; public: inline matrix(int r,int c){ this->COLS=r; this->ROWS=c; } template<class T2> friend ostream& info(ostream& os); }; i tried in so many ways to implement the info function.but none is succeed. i want to use it in main f...

C++: Print only one char

Hi, When I read one char* from std::cin and I want to write it to std::cout, it prints until it finds a \0 in memory. So what did was: char c; cin >> c; char* pChar = &c; pChar++; *pChar = '\0'; println(&c); // My own method: void println(char * str) { cout << str << endl; } But I don't think this is a safe action. Is there a safer ...

byte stream and character stream

Hi, Please explain byte stream and character stream files. What exactly these means , is microsoft word document is byte oriented or character oriented ? Thanks ...

Connecting std::basic_ofstream<unsigned char> to a FIFO. bad_cast exceptions

Using gcc 4.4.3 on Linux 2.6.32, I get bad_cast exceptions when connecting std::basic_ofstream to a FIFO. Stepping though the debugger, I can see that the error is generated at various places in the standard library because the _M_codecvt member of the stream or filebuf object is NULL. Exactly where it happens depends on the order of op...

C++ Draw program, split in groups of two

I would like to make a draw application. I want to enter user names until eg "end" is entered and then the program to split them in groups of two. Can you suggest any examples? I don't know how to start! If possible, I want to be Cross-platform. If it isn't possible I want linux. ...

Recommendations for a C++ polymorphic, seekable, binary I/O interface

I've been using std::istream and ostream as a polymorphic interface for random-access binary I/O in C++, but it seems suboptimal in numerous ways: 64-bit seeks are non-portable and error-prone due to streampos/streamoff limitations; currently using boost/iostreams/positioning.hpp as a workaround, but it requires vigilance Missing opera...

Strange Access Denied warning when running the simplest C++ program.

I am just starting to learn C++ (coming from a Java background) and I have come across something that I can't explain. I am working through the C++ Primer book and doing the exercises. Every time I get to a new exercise I create a new .cpp file and set it up with the main method (and any includes I think I will need) e.g.: #include <l...

Input/output stream abstraction layers for plain C

Are there any widely used I/O stream abstraction layers for plain C? By an I/O stream abstraction layer I mean any layer that at least allows the creation of custom read/write functions. For C++, there's the standard iostream and boost::iostreams. For glibc users, there's a possibility to use custom streams. These won't do any good if t...

Stream extraction within if/else

Assuming the stream extraction won't fail, will this if( !(stream >> token) ) throw runtime_error( "Unexpected end of recipe." ); else if( token == "something" ) // do something else throw runtime_error( "Unknown token" ); Work like this if( !(stream >> token) ) throw std::runtime_error( "Unexpected end of recipe." );...

C++ iostreams question

Hello! I have the following question on boost::iostreams. If someone is familiar with writing filters, I would actually appreciate your advices / help. I am writing a pair of multichar filters, that work with boost::iostream::filtering_stream as data compressor and decompressor. I started from writing a compressor, picked up some algor...