Question

I receive a binary file via POST in a C++ CGI script and I'm using the Cgicc library to get its contents like so:

std::ofstream myfile;
myfile.open ("file.out", std::ios::in | std::ios::binary);
try
{
    cgicc::Cgicc cgi;
    cgicc::const_file_iterator file = cgi.getFile("bitmap");
    if(file != cgi.getFiles().end())
    {
        file->writeToStream(myfile);
    }
}

catch(std::exception &exception)
{
    std::cout << exception.what();
}

The result is a binary file containing the bytes.

Now, because each byte should represent one pixel of an 8 bit bitmap file, I want to construct the entire bitmap file. In order to achieve this, I think I can use the easyBMP library, but since I need to create the image pixel by pixel, I need to somehow iterate over the received bytes. Does anyone know how this can be achieved? Can I get an iterator somehow to an std::ostream / std::ostrstream / std::ostringstream?

std::ostringstream stream;
file->writeToStream(stream);
//foreach byte in stream do { ... }
Was it helpful?

Solution

If you use std::ostringstream you can get std::string from it, using std::ostringstream::str function http://cplusplus.com/reference/iostream/ostringstream/str/ . Also, you can open your file and read it...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top