Note that there are some explanatory texts on larger screens.

plurals
  1. POOfstream not creating a new file correctly
    primarykey
    data
    text
    <p>I've tried to write a simple database program. The problem is that ofstream does NOT want to make a new file.</p> <p>Here's an extract from the offending code.</p> <pre><code>void newd() { string name, extension, location, fname; cout &lt;&lt; "Input the filename for the new database (no extension, and no backslashes)." &lt;&lt; endl &lt;&lt; "&gt; "; getline(cin, name); cout &lt;&lt; endl &lt;&lt; "The extension (no dot). If no extension is added, the default is .cla ." &lt;&lt; endl &lt;&lt; "&gt; "; getline(cin, extension); cout &lt;&lt; endl &lt;&lt; "The full directory (double backslashes). Enter q to quit." &lt;&lt; endl &lt;&lt; "Also, just fyi, this will overwrite any files that are already there." &lt;&lt; endl &lt;&lt; "&gt; "; getline(cin, location); cout &lt;&lt; endl; if (extension == "") { extension = "cla"; } if (location == "q") { } else { fname = location + name + "." + extension; cout &lt;&lt; fname &lt;&lt; endl; ofstream writeDB(fname); int n = 1; //setting a throwaway inteher string tmpField, tmpEntry; //temp variable for newest field, entry for(;;) { cout &lt;&lt; "Input the name of the " &lt;&lt; n &lt;&lt; "th field. If you don't want any more, press enter." &lt;&lt; endl; getline(cin, tmpField); if (tmpField == "") { break; } n++; writeDB &lt;&lt; tmpField &lt;&lt; ": |"; int j = 1; //another one for (;;) { cout &lt;&lt; "Enter the name of the " &lt;&lt; j++ &lt;&lt; "th entry for " &lt;&lt; tmpField &lt;&lt; "." &lt;&lt; endl &lt;&lt; "If you don't want any more, press enter." &lt;&lt; endl; getline(cin, tmpEntry); if (tmpEntry == "") { break; } writeDB &lt;&lt; " " &lt;&lt; tmpEntry &lt;&lt; " |"; } writeDB &lt;&lt; "¬"; } cout &lt;&lt; "Finished writing database. If you want to edit it, open it." &lt;&lt; endl; } } </code></pre> <p>EDIT: OK, just tried</p> <pre><code>#include &lt;fstream&gt; using namespace std; int main() { ofstream writeDB ("C:\\test.cla"); writeDB &lt;&lt; "test"; writeDB.close(); return 0; } </code></pre> <p>and that didn't work, so it is access permission problems.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload