How can I declare a struct?
<p>I am currently learning C++ and trying to understand the usage of structs.</p>

<p>in C++. As far as I'm aware, if you want to define a function after the main() function, you have to <strong>declare</strong> it beforehand, like in this function (Please tell me if I'm wrong with it):</p>

<pre><code>#include "stdafx.h"
#include &lt;iostream&gt;
#include &lt;string&gt;

void printText(std::string); // &lt;-- DECLARATION

int main()
{
    std::string text = "This text gets printed.";
    printText(text);
}

void printText(std::string text)
{
    std::cout &lt;&lt; text &lt;&lt; std::endl;
}
</code></pre>

<p>My question now is if there is a way to do the same with structs. I don't want having to always define a struct before the main() function, just because I prefer it like that. However, I get an error when I try doing it like that:</p>

<pre><code>//THIS program DOESN'T work.    
#include "stdafx.h"
#include &lt;iostream&gt;
#include &lt;string&gt;

struct Products {std::string}; // &lt;-- MY declaration which DOESN'T work

int main()
{
    Products products;
    products.product = "Apple";
    std::cout &lt;&lt; products.product &lt;&lt; std::endl;
}

struct Products
{
    std::string product;
};
</code></pre>

<p>When I delete the decleration and instead define the struct <strong>before</strong> the main function, the program works so I assume I'm somehow wrong with the decleration:</p>

<pre><code>//THIS program DOES work
#include "stdafx.h"
#include &lt;iostream&gt;
#include &lt;string&gt;

struct Products
{
    std::string product;
};

int main()
{
    Products products;
    products.product = "Apple";
    std::cout &lt;&lt; products.product &lt;&lt; std::endl;
}
</code></pre>

<p>Could someone tell me if there is some way to declare a struct like that? Bear with me if I have any major mistake in the code, I'm just a beginner.
Thanks in advance!</p>