Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ copy text file program using header file
    primarykey
    data
    text
    <p>Hello i am making a program that is supposed to copy a text file. The text file is just 3 lines of text at the moment. The textFileCopy function is supposed to read in a text file given by the filenamein array and then output a copy of the text file given by the filenameout array.</p> <p>This is my main.cpp file. In this file the program requires the user to send an input filename and an output filename as arguments which i have just done using the command argument box in visual studio, the command argument box contains "input.txt output.txt" so this means that argv[1] contains the input file and argv[2] contains the output file which is to be created</p> <pre><code>#include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;string&gt; using namespace std; #include "FileUtilities.h" int main(int argc, char **argv) { FileUtilities fileUtil; fileUtil.textFileCopy(false, false); if (argc !=3) { cerr &lt;&lt; "Usage: " &lt;&lt; argv[0] &lt;&lt; " &lt;input filename&gt; &lt;output filename&gt;" &lt;&lt; endl; int keypress; cin &gt;&gt; keypress; return -1; } fileUtil.textFileCopy(argv[1], argv[2]); int keypress; cin &gt;&gt; keypress; } </code></pre> <p>And this is the FileUtilities.h file which declares the textFileCopy function</p> <pre><code>#include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;string&gt; using namespace std; #pragma once class FileUtilities { public: bool textFileCopy(char filenamein[], char filenameout[]); }; </code></pre> <p>And here is the matching FileUtilities.cpp file including textFileCopy function</p> <pre><code>#include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;string&gt; #include "FileUtilities.h" bool FileUtilities::textFileCopy(char filenamein[], char filenameout[]) { ifstream fin(filenamein); if(fin.is_open()) { ofstream fout(filenameout); char c; while(fin.good()) { fin.get(c); fout &lt;&lt; c; } fout.close(); fin.close(); return true; } return false; } </code></pre> <p>I am having trouble creating the function defined in the .h file in the .cpp file and i get errors with this line <code>FileUtilities::textFileCopy(char filenamein[], char filenameout[])</code> from the .cpp file. I know the actual code in the function works its just that first line</p> <p>UPDATE</p> <p>Ok so i have put bool before the function.</p> <p>Now the program compiles and i get an error in a dialog box as follows</p> <p>"Microsoft Visual C++ Debug Library</p> <p>Debug Assertion Failed!</p> <p>Program: .....Parser.exe file f:\dd\vctools\crt_bld\Self_x86\crt\src\fopen.c Line 53</p> <p>Expression: (file!=NULL)"</p> <p>then it opens a file "dbghook.c" in visual studio</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.
    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