<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">\section{examples/doAdd.cpp}
Show how to use a network already trained and saved to a binary file. In this case, a network trained to simply perform sums between two real numbers, that should have already been created using learnAdd.



\begin{DocInclude}\begin{verbatim}
#include &lt;iostream&gt;
#include &lt;neural++.hpp&gt;

using namespace std;
using namespace neuralpp;

#define NETFILE "adder.net"

int main()  {
        double a,b;
        NeuralNet net;

        // Load the pre-trained network from "adder.net" file
        try  {
                net = NeuralNet(NETFILE);
        }

        catch (NetworkFileNotFoundException e)  {
                cerr &lt;&lt; "Fatal error while opening " &lt;&lt; NETFILE &lt;&lt; ": " &lt;&lt; e.what();
                return 1;
        }

        cout &lt;&lt; "First number to add: ";
        cin &gt;&gt; a;

        cout &lt;&lt; "Second number to add: ";
        cin &gt;&gt; b;

        vector&lt;double&gt; v;
        v.push_back(a);
        v.push_back(b);

        // Set the numbers just read as input values, propagate those values, and get
        // the output
        net.setInput(v);
        net.propagate();
        cout &lt;&lt; "Neural net output: " &lt;&lt; net.getOutput() &lt;&lt; endl;

        return 0;
}

\end{verbatim}
\end{DocInclude}
 </pre></body></html>