iostream

std::stringstream and std::ios::binary

I want to write to a std::stringstream without any transformation of, say line endings. I have the following code: void decrypt(std::istream& input, std::ostream& output) { while (input.good()) { char c = input.get() c ^= mask; output.put(c); if (output.bad()) { throw std::ru...

Is it possible to use CIN and QT ???

within Qt is it possible to use cin?? I can use cout but cannot find anywhere where it shows how to use ciin within a Qt Console application many thanks, gda2004 ...

How many characters can read by using the readline() method in java?

I using readLine() method for reading the text, but i am not aware of how many text can read that method. Ex. String str = in.readLine(); how many texts can read and store on "str"? ...

Problem with iostream, my output endl are littles squares.

I have a problem with with my output when I write to I file I get squares when I put endl to change lines. std::ofstream outfile (a_szFilename, std::ofstream::binary); outfile<<"["<<TEST<<"]"<<std::endl; I get something like this in my file plus the other outputs don't write on the next line but on the same one. [TEST]square appa...

Prevent scientific notation in ostream when using << with double

I need to prevent my double to print in scientific notation in my file, when I do this outfile<<X; ...

overriding ctype<wchar_t>

I'm writing a lambda calculus interpreter for fun and practice. I got iostreams to properly tokenize identifiers by adding a ctype facet which defines punctuation as whitespace: struct token_ctype : ctype<char> { mask t[ table_size ]; token_ctype() : ctype<char>( t ) { for ( size_t tx = 0; tx < table_size; ++ tx ) { t[tx] = isal...

iostream, some questions

I've seen people do things like.... istringstream ibuf; if (ibuf >> zork >> iA >> Comma >> iB) now I guess the value depends on what >>iB exposes but exactly what is that and what does it mean? Does true mean all the ietms were extracted? Also, after an expression like ibuf >> zork >> iA >> Comma >> iB; is there any way to ...

Why can't I create a std::stack of std::ifstreams?

Why does the following not work: #include <iostream> #include <fstream> #include <stack> std::stack<std::ifstream> s; -PT ...

C++ iostreams and python

Is it possible to interoperate with a C++ iostream and python? I'm using boost-python and want to wrap a function that has istream and ostream as arguments. ...

Possible to create a dual-seekable Boost Iostream using a file_descriptor?

I'm trying to update a random-access binary file using the std::iostream interface with separate get/put positions managed via seekg/seekp. Everything works fine with stringstream, but when I create a file descriptor-based stream using Boost.Iostream (specifically boost::iostreams::stream<boost::iostreams::file_descriptor>), the get/put ...

seekg() failing mysteriously

I have a 2884765579 bytes file. This is double checked with this function, that returns that number: size_t GetSize() { const size_t current_position = mFile.tellg(); mFile.seekg(0, std::ios::end); const size_t ret = mFile.tellg(); mFile.seekg(current_position); return ret; } I then do: mFile.se...

The question regarding cerr cout and clog

Can anybody explain the difference between cerr cout and clog and why does different objects are proposed? I know the differences are as below: 1) cout can redirected but cerr can't 2) clog can use buffer. I am confused about the point 2, I am grateful if anybody can elaborate it more. ...

When do c++ stream objects use mutexes?

In the answer to this question ovanes states: Please be aware that boost::lexical_cast is much slower as atoi. I also use it very often in a performance non-critical code. The problem with lexical_cast is that it uses stringstream for conversion. If you are working in a multi-threaded environement any stream class from ...

one question about iostream cout in C++

Hi In such code, what it is called, \\n like this? cout<<"Hello\\n \'world\'!"; What's the basic rule about such characters? ...

Writing my own iostream utility class: Is this a good idea?

I have an application that wants to read word by word, delimited by whitespace, from a file. I am using code along these lines: std::istream in; string word; while (in.good()) { in>>word; // Processing, etc. ... } My issue is that the processing on the words themselves is actually rather light. The major time consumer is...

Piping EOF problems with stdio and C++/Python

I got some problems with EOF and stdio in a communication pipeline between a python process and a C++ program. I have no idea what I am doing wrong. When I see an EOF in my program I clear the stdin and next round I try to read in a new line. The problem is: for some reason the getline function immediatly (from the second run always, the...

How could I redirect stdin (istream) in wxWidgets?

Hi, I'm trying to figure out how to redirect istream to wxwidgets. I was able to accomplish redirecting ostream, here's how (so you know what I mean): wxTextCtrl* stdoutctrl = new wxTextCtrl(...); wxStreamToTextRedirector redirect(stdoutctrl); //Redirect ostream std::cout<<"stdout -- does this work?"<<std::endl; //It worked. I'...

Why do I need to include both the iostream and fstream headers to open a file

#include <iostream> #include <fstream> using namespace std; int main () { ofstream myfile; myfile.open ("test.txt"); return 0; } fstream is derived from iostream, why should we include both in the code above? I removed fstream, however, there is an error with ofstream. My question is ofstream is derived from ostream, why fstrea...

How to switch iostream from binary to text mode and vice versa?

I want to read both formatted text and binary data from the same iostream. How can I do that? Why? Imagine this situation: You have different resources, and resource loaders for them, that take a std::istream as a parameter. And there are a "resource source" that provides these streams. Resources can be both text and binary and I need t...

How can I change the precision of printing with the stl?

This might be a repeat, but my google-fu failed to find it. I want to print numbers to a file using the stl with the number of decimal places, rather than overall precision. So, if I do this: int precision = 16; std::vector<double> thePoint(3); thePoint[0] = 86.3671436; thePoint[0] = -334.8866574; thePoint[0] = 24.2814; ofstream file...