Vector print duplicate Values : <p>I've written a program in C++ to print out a vector of pointers to my classes <code>Vehicle</code> is a parent class for <code>Car</code>.
All the functions work properly yet the program itself prints wrong values, changing them after all iterations of the loop.
Here's the code:</p>

<pre><code>int main() {
std::vector&lt;Vehicle *&gt; vehs;

for (int i = 0; i &lt; 3; i++) {
    std::string Id;
    std::cout &lt;&lt; "Id: " &lt;&lt; std::endl;
    getline(std::cin, Id);

    std::string Marka;
    std::cout &lt;&lt; "Marka: " &lt;&lt; std::endl;
    getline(std::cin, Marka);

    double Par;
    std::cout &lt;&lt; "Parametr: " &lt;&lt; std::endl;
    std::cin &gt;&gt; Par;
    getchar();

    Car car(Id, Marka, Par);
    vehs.push_back(&amp;car);

    std::cout &lt;&lt; to_string(vehs.cbegin(), vehs.cend());

}
</code></pre>

<p>And the result is as follows:</p>

<pre><code>Id:
A
Marka:
A
Parametr:
1
A : A
Id:
B
Marka:
B
Parametr:
2
B : B
B : B
Id:
C
Marka:
C
Parametr:
3
C : C
C : C
C : C
</code></pre>

<p>As you can see, the contents of <code>vehs</code> change even, if I do not want them to.</p>

<p>The <code>to_string</code> looks like that:</p>

<pre><code>std::string to_string (const Vehicle&amp; vehicle){
std::ostringstream oss;
oss &lt;&lt; vehicle.getId() &lt;&lt; " : "&lt;&lt; vehicle.getBrand();
return oss.str();
}


std::string to_string(std::vector&lt;Vehicle*&gt;::const_iterator vehicles_begin,
std::vector&lt;Vehicle*&gt;::const_iterator vehicles_end){
std::ostringstream  oss;
for(auto it = vehicles_begin; it!= vehicles_end; it++ ){
    oss &lt;&lt; to_string(**it) &lt;&lt; std::endl;
}
return oss.str();
}
</code></pre>
