Project

General

Profile

Can't move std::ostringstream to wt::wresource->write()

Added by Mark Travis almost 2 years ago

I have the following as private: in my header file:
std::ostringstream outputStream;

I have an object I created to override handleRequest in WResource called fileResource_ in the code below.

The following code unwraps a std::arraystd::string to an ostringstream which should then feed the WResource object as the contents of a file that will be automatically downloaded:
(The file is a text file and each std::string represents a line in the file)

    for (std::string singleString: *multipleStringsArray_->arrayOfStdStrings_){
        outputStream << singleString << std::endl;
    }
    fileResource_->fileName = std::move(fileName);
    fileResource_->write(outputStream.flush());

I've tried all manner of things to get the ostringstream in to the ostream (using the write() function) but it doesn't work. (I tried it with just outputStream and just tried it with outputStream.flush())

What I get right now is an automatic download that works with the appropriate name that I want, but the filesize is zero bytes.

I can see the text in ostringstream when write() is called, but once inside the write() function, there is nothing in the appropriate areas of "out".


Replies (1)

RE: Can't move std::ostringstream to wt::wresource->write() - Added by Mark Travis almost 2 years ago

Wow, was I overcomplicating this.....

I threw away everything. Created a std::string and std::ostringstream, then dumped the ostringstream to the string.
Then I created a var in the header file of my overridden wresource that is a std::string, that I then used to dump the above output to result.out() in the response() override. done.

    (1-1/1)