[#BloombergLP-balxml-Encoder-encode-03] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/balxml.adoc[balxml]::xref:BloombergLP/balxml/Encoder.adoc[Encoder]::encode :relfileprefix: ../../../ :mrdocs: Encode the specified non‐modifiable `object` to the specified `stream`. Return a reference to `stream`. If an encoding error is detected, `stream.fail()` will be true on return. Note that the encoder will use encoder options, error and warning streams specified at the construction time. IMPORTANT: The use of `stream.fail()` to communicate errors to the caller has two consequences: 1) if `stream` is the same as the `errorStream` passed to the constructor, then the error message may be suppressed (because of the output/error stream becoming invalidated) and 2) it is important to call `stream.clear()` after testing the stream state. To avoid these issues, we recommend that you use use `encodeToStream`, above, instead of this version of `encode`. == Synopsis Declared in `<balxml_encoder.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class TYPE> std::ostream& encode( std::ostream& stream, TYPE const& object); ---- [.small]#Created with https://www.mrdocs.com[MrDocs]#