user37060: I need a function that has the basic functionality of the Print library, accepting different kinds of argument types and parsing them. However, I would like to then store the result in a string/char array. Does anybody know how I might utilize the Print library to do so?

user7508: You can get all the functionality of Print by creating your own class
that inherits from it. For this, you only need to implement the
size_t write(uint8_t) method that prints a single character. Here is a
simple class that inherits from both Print and String, i.e. you get
a String you can print() and println() into:
// A String you can print() and println() into.
class PrintString : public Print, public String
{
public:
    PrintString() : String() {}

    size_t write(uint8_t c) {
        *this += (char) c;
        return 1;
    }
};

And here is how you could use it:
PrintString answer;
answer.print("The answer is ");
answer.println(42);


37060: <p>I need a function that has the basic functionality of the Print library, accepting different kinds of argument types and parsing them. However, I would like to then store the result in a string/char array. Does anybody know how I might utilize the Print library to do so?</p>
 7508: <p>You can get all the functionality of <code>Print</code> by creating your own class
that inherits from it. For this, you only need to implement the
<code>size_t write(uint8_t)</code> method that prints a single character. Here is a
simple class that inherits from both <code>Print</code> and <code>String</code>, i.e. you get
a <code>String</code> you can <code>print()</code> and <code>println()</code> into:</p>

<pre><code>// A String you can print() and println() into.
class PrintString : public Print, public String
{
public:
    PrintString() : String() {}

    size_t write(uint8_t c) {
        *this += (char) c;
        return 1;
    }
};
</code></pre>

<p>And here is how you could use it:</p>

<pre><code>PrintString answer;
answer.print("The answer is ");
answer.println(42);
</code></pre>
