<div class="fragment"><div class="line"><span class="comment">// ***************************************************************** -*- C++ -*-</span></div>
<div class="line"><span class="comment">// iptceasy.cpp, $Rev: 3090 $</span></div>
<div class="line"><span class="comment">// The quickest way to access, set or modify IPTC metadata.</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="doc/exiv2_8hpp.html" title="Include all Exiv2 header files.">exiv2/exiv2.hpp</a>&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;iomanip&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;cassert&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* <span class="keyword">const</span> argv[])</div>
<div class="line"><span class="keyword">try</span> {</div>
<div class="line">    <span class="keywordflow">if</span> (argc != 2) {</div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;Usage: &quot;</span> &lt;&lt; argv[0] &lt;&lt; <span class="stringliteral">&quot; file\n&quot;</span>;</div>
<div class="line">        <span class="keywordflow">return</span> 1;</div>
<div class="line">    }</div>
<div class="line">    std::string file(argv[1]);</div>
<div class="line"></div>
<div class="line">    <a name="_a1"></a><a class="code" href="doc/classExiv2_1_1IptcData.html" title="A container for IPTC data. This is a top-level class of the Exiv2 library.">Exiv2::IptcData</a> iptcData;</div>
<div class="line"></div>
<div class="line">    iptcData[<span class="stringliteral">&quot;Iptc.Application2.Headline&quot;</span>] = <span class="stringliteral">&quot;The headline I am&quot;</span>;</div>
<div class="line">    iptcData[<span class="stringliteral">&quot;Iptc.Application2.Keywords&quot;</span>] = <span class="stringliteral">&quot;Yet another keyword&quot;</span>;</div>
<div class="line">    iptcData[<span class="stringliteral">&quot;Iptc.Application2.DateCreated&quot;</span>] = <span class="stringliteral">&quot;2004-8-3&quot;</span>;</div>
<div class="line">    iptcData[<span class="stringliteral">&quot;Iptc.Application2.Urgency&quot;</span>] = uint16_t(1);</div>
<div class="line">    iptcData[<span class="stringliteral">&quot;Iptc.Envelope.ModelVersion&quot;</span>] = 42;</div>
<div class="line">    iptcData[<span class="stringliteral">&quot;Iptc.Envelope.TimeSent&quot;</span>] = <span class="stringliteral">&quot;14:41:0-05:00&quot;</span>;</div>
<div class="line">    iptcData[<span class="stringliteral">&quot;Iptc.Application2.RasterizedCaption&quot;</span>] = <span class="stringliteral">&quot;230 42 34 2 90 84 23 146&quot;</span>;</div>
<div class="line">    iptcData[<span class="stringliteral">&quot;Iptc.0x0009.0x0001&quot;</span>] = <span class="stringliteral">&quot;Who am I?&quot;</span>;</div>
<div class="line"></div>
<div class="line">    <a name="_a2"></a><a class="code" href="doc/classExiv2_1_1StringValue.html" title="Value for string type.">Exiv2::StringValue</a> value;</div>
<div class="line">    value.<a name="a3"></a><a class="code" href="doc/classExiv2_1_1StringValueBase.html#a6882ba90138a30fcf2123c74f928a75e" title="Read the value from buf. This default implementation uses buf as it is.">read</a>(<span class="stringliteral">&quot;very!&quot;</span>);</div>
<div class="line">    iptcData[<span class="stringliteral">&quot;Iptc.Application2.Urgency&quot;</span>] = value;</div>
<div class="line"></div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;Time sent: &quot;</span> &lt;&lt; iptcData[<span class="stringliteral">&quot;Iptc.Envelope.TimeSent&quot;</span>] &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span>;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Open image file</span></div>
<div class="line">    <a class="code" href="doc/classExiv2_1_1Image.html#a89ad3ffe7a4e8a943d267d77843415fb" title="Image auto_ptr type.">Exiv2::Image::AutoPtr</a> image = <a name="a4"></a><a class="code" href="doc/classExiv2_1_1ImageFactory.html#aba929c4ca4a71625d12bcb97bcc28161" title="Create an Image subclass of the appropriate type by reading the specified file. Image type is derived...">Exiv2::ImageFactory::open</a>(file);</div>
<div class="line">    assert (image.get() != 0);</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Set IPTC data and write it to the file</span></div>
<div class="line">    image-&gt;setIptcData(iptcData);</div>
<div class="line">    image-&gt;writeMetadata();</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="line"><span class="keywordflow">catch</span> (<a name="_a5"></a><a class="code" href="doc/classExiv2_1_1AnyError.html" title="Error class interface. Allows the definition and use of a hierarchy of error classes which can all be...">Exiv2::AnyError</a>&amp; e) {</div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;Caught Exiv2 exception &#39;&quot;</span> &lt;&lt; e &lt;&lt; <span class="stringliteral">&quot;&#39;\n&quot;</span>;</div>
<div class="line">    <span class="keywordflow">return</span> -1;</div>
<div class="line">}</div>
</div><!-- fragment -->
