Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can create a class derived from <code>std::streambuf</code> which uses the Android specific functions to send the produced sequence of characters. I don't know where the default implementation of <code>std::cout</code> sends characters on Android, however. Basically, this would look something like this:</p> <pre><code>class androidbuf : public std::streambuf { public: enum { bufsize = 128 }; // ... or some other suitable buffer size androidbuf() { this-&gt;setp(buffer, buffer + bufsize - 1); } private: int overflow(int c) { if (c == traits_type::eof()) { *this-&gt;pptr() = traits_type::to_char_type(c); this-&gt;sbumpc(); } return this-&gt;sync()? traits_type::eof(): traits_type::not_eof(c); } int sync() { int rc = 0; if (this-&gt;pbase() != this-&gt;pptr()) { char writebuf[bufsize+1]; memcpy(writebuf, this-&gt;pbase(), this-&gt;pptr() - this-&gt;pbase()); writebuf[this-&gt;pptr() - this-&gt;pbase()] = '\0'; rc = __android_log_write(ANDROID_LOG_INFO, "std", writebuf) &gt; 0; this-&gt;setp(buffer, buffer + bufsize - 1); } return rc; } char buffer[bufsize]; }; </code></pre> <p>To actually set up <code>std::cout</code> to write to this stream buffer, you would do something like this in your <code>main()</code> function:</p> <pre><code>int main() { std::cout.rdbuf(new androidbuf); ... } </code></pre> <p>This create a memory leak for the one <code>androidbuf</code> stream which is, however, somewhat intentional: the stream may be written to after <code>main()</code> is exited and it is flushed when when <code>std::cout</code> gets destroyed. If you don't want this, you could either restore <code>std::cout</code>'s original stream buffer or set it to null and delete the return from <code>rdbuf()</code>:</p> <pre><code> // avoid a one-time resource leak but don't get output afterwards: delete std::cout.rdbuf(0); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload