istream

substream from istream

偶尔善良 提交于 2019-12-04 10:20:17
Suppose I have an ifstream which represents a large file containing lots of sub-files aggregated together. I want to be able to create a "sub" istream from the larger ifstream (given a size and offest) representing a part of the file so other code can read from that substream as if it was an independent istream . Any ideas on how I might accomplish this? EDIT - I would prefer to avoid boost. BHS This is an example of a streambuf "filter" that reads from a contained streambuf starting at a specified location and reading up to a specified size. You create substreambuf , passing your original

How to convert QByteArray to std::istream or std::ifstream?

我的梦境 提交于 2019-12-03 18:10:51
问题 I want to create istream from QByteArray at runtime, without saving a physical file in memory of QByteArray . I found that there are many ways to do the opposite conversion, i.e. istream to QByteArray , but not this one. How to accomplish that? 回答1: To read via std::istringstream from QByteArray seems quite easy: testQByteArray-istream.cc : #include <iostream> #include <sstream> #include <QtCore> int main() { qDebug() << "Qt Version:" << QT_VERSION_STR; // make a QByteArray QByteArray data(

download a file using windows IStream

随声附和 提交于 2019-12-03 08:50:58
I'm implementing dragging a virtual file out of a website and onto the desktop with an activex control. How do I create an IStream on my http url, so Windows can execute the drop? The example I'm looking at uses SHCreateStreamOnFile to copy a local file; there must be an analogous function for other types of streams like http file download. How about using the URL Moniker Functions . You can use the URLDownloadToFile (blocking function), or URLOpenPullStream (asynchronous). 来源: https://stackoverflow.com/questions/3168145/download-a-file-using-windows-istream

Using the same istream with a resizeable streambuf in boost::asio

Deadly 提交于 2019-12-02 18:34:46
问题 I am reading data off a socket using boost asio async_read(). I have the following members of the reader class which persist through the lifetime of the program: boost::asio::streambuf recv_data; std::istream stream_is(&recv_data); The async_read call looks like this: boost::asio::async_read(ep_ptr->get_sock(), recv_data, boost::asio::transfer_exactly(n), boost::bind(&IProtocol::handle_data_recv, &protocol, boost::asio::placeholders::error)); My question is, what would happen if I am reading

eof of istream in C++

╄→гoц情女王★ 提交于 2019-12-02 01:28:34
问题 bool ios::eof ( ) const; According to the library, The function returns true if the eofbit stream's error flag has been set by a previous i/o operation. This flag is set by all standard input operations when the End Of File is reached in the sequence associated with the stream. I wrote a program to run some tests: int main(int argc, char *argv[]) { ifstream ifs(argv[1]); float f; ifs >> f; cout << ifs.eof() << endl; //check if eofbit set ifs.close(); } I tested 2 files, testcase1.txt and

How does istream::operator>>( const char& ) as no such function is implemented?

我只是一个虾纸丫 提交于 2019-12-01 23:03:54
问题 Looking at istream documentation, you will see that there is no implementation of function istream &operator>>( char& ) , but if you compile and run the code below, it will work just as expected. #include<iostream> int main( ) { char c; std::cin >> c; std::cout << c << std::endl; return( 0 ); } Given cin is an object for class istream, which specialization of operator>> is called when std::cin >> c; is executed? 回答1: operator>> also is implemented as non-member functions. istream& operator>>

Getting an IStream from an OleVariant

寵の児 提交于 2019-12-01 21:56:44
I am using Delphi along with WinHTTP to do an HTTP request to download some files from the internet, and I can do the request but I don't know how to get the IStream from the OleVariant that is returned from ResponseStream . I have spent a lot of time googling but I can't figure out how to do it. Here is what I have tried: var req: IWinHTTPRequest; instream: IStream; begin req := CoWinHTTPRequest.Create; req.Open('GET', 'http://google.com', false); req.Send(''); if req.Status <> 200 then begin ShowMessage('failure'#10 + req.StatusText); FreeAndNil(req); Application.Terminate; end; instream :=

eof of istream in C++

放肆的年华 提交于 2019-12-01 20:20:19
bool ios::eof ( ) const; According to the library, The function returns true if the eofbit stream's error flag has been set by a previous i/o operation. This flag is set by all standard input operations when the End Of File is reached in the sequence associated with the stream. I wrote a program to run some tests: int main(int argc, char *argv[]) { ifstream ifs(argv[1]); float f; ifs >> f; cout << ifs.eof() << endl; //check if eofbit set ifs.close(); } I tested 2 files, testcase1.txt and testcase2.txt. testcase1.txt was generated in the terminal with cat , [Ctrl-D] was used to end input: [~/C+

GCC 4.7 istream::tellg() returns -1 after reaching EOF

泪湿孤枕 提交于 2019-12-01 18:00:50
问题 The following code works with gcc 4.4. But gcc 4.7 will give assertion failure. #include <assert.h> #include <iostream> #include <sstream> using namespace std; int main() { string input("abcdefg"); stringstream iss(input); ostringstream oss; oss << iss.rdbuf(); assert (!iss.eof()); (void) iss.peek(); assert (iss.eof()); // the following assertion will fail with gcc 4.7 assert( streamoff(iss.tellg()) == streamoff(input.length()) ); return 0; } In gcc 4.7, if the istream has reached EOF, tellg(

GCC 4.7 istream::tellg() returns -1 after reaching EOF

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 17:24:39
The following code works with gcc 4.4. But gcc 4.7 will give assertion failure. #include <assert.h> #include <iostream> #include <sstream> using namespace std; int main() { string input("abcdefg"); stringstream iss(input); ostringstream oss; oss << iss.rdbuf(); assert (!iss.eof()); (void) iss.peek(); assert (iss.eof()); // the following assertion will fail with gcc 4.7 assert( streamoff(iss.tellg()) == streamoff(input.length()) ); return 0; } In gcc 4.7, if the istream has reached EOF, tellg() will return -1. no pubseekoff() nor seekoff() will be called In gcc 4.4 it is not a problem. Which is