Permanently storing a buffer value
<p>I'm trying to parse the lines of a text file and then store them inside of a <code>vector&lt;string&gt;</code>.    I'm coming from a Java background and am confused on how C++ handles assigning stuff to the value of a buffer.  Here is my code:</p>

<pre><code>string line;
vector&lt;string&gt; adsList;
ifstream inputFile;
inputFile.open("test.txt");
while(getline(inputFile, line))
{
    adsList.push_back(line);
}
</code></pre>

<p>In Java, when adding to a data structure a copy of the object is made and then that copy is inserted.  In C++, my understanding is that the data structures only hold references so that any operation is very fast.  What is the proper way to achieve what I want to do in C++?  I have also tried the following code:</p>

<pre><code>vector&lt;string&gt; adsList;
string line;
ifstream inputFile;
inputFile.open("test.txt");
while(getline(inputFile, line))
{
    string *temp = new string;
    *temp = line;
    adsList.push_back(*temp);
}
</code></pre>

<p>With my reasoning here being that creating a new string object and storing that would preserve it after being destroyed each loop iteration.  C++ seems to handle this completely opposite of Java and I am having a hard time wrapping my head around it.</p>

<p>edit: here is what test.txt looks like:</p>

<pre><code>item1 item1 item1
item2 item2 item2
item3 item3 item3
item4 item4 item4
</code></pre>

<p>I'm trying to store each line as a string and then store the string inside my vector.  So the front of the vector would have a string with value "item1 item1 item1".</p>
