opening and reading a file whose name is given at runtime
<p>My problem is how to use correctly the function <code>infile.open()</code>.</p>

<p>I have a class that, among the others, has the following public properties:</p>

<pre><code>class myclass {
public:
int rows
int columns
const char* array_file
}
</code></pre>

<p>All values are given at run-time.</p>

<p>When I call the function that uses a member of the class I have (pt is a pointer to a member of the class)</p>

<pre><code>#include &lt;vector&gt;
#include &lt;fstream&gt;
#include &lt;iostream&gt;
typedef std::vector&lt; std::vector&lt;int&gt; &gt; Matrixint;

void function(myclass* pt) { 
    Matrixint array_name(pt-&gt;rows, std::vector&lt;int&gt;(pt-&gt;columns));

    std::ifstream infile;

    infile.open("%s", pt-&gt;array_file); // my problem: is this correct?
    for (int a = 0; a &lt; pt-&gt;rows; a++) {
         for (int b = 0; b &lt; pt-&gt;columns; b++) {
               infile &gt;&gt; array_name[a][b] ;
         }
    }
    infile.close();

}
</code></pre>

<p>Is this way of opening/reading the file correct?</p>

<p>The data in the file will be formatted as in <a href="http://stackoverflow.com/questions/5239689/reading-data-from-file-into-array">this question</a> (please note: only the array will be present in the file, no other data)</p>
