Hello, my name is Morgan and I am starting to learn visual studio c++ and would
like to request help with an issue I am having. I have read a few threads on this
forum and they are really helpful so I feel like you guys will give me an answer
at your earliest convenience.
I am dearly sorry if this has been asked/posted before.
Here's my code which is things I am learning right now as a beginner..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
char ch;
ifstream infile("C:\\test.txt");
ofstream outfile("C:\\test1.txt");
if (!infile)
clog << "File not found" << endl << endl;
else
clog << "File succesfully found..." << endl << endl;
if (!outfile)
clog << "New file could not be written" << endl << endl;
else
clog << "New file succesfully written." << endl << endl;
while (infile && infile.get(ch) )
outfile.put(ch);
|
The if statement works fine and so does the last part for writing the file.
However, I've tested it out without adding the "C:\\" to the file names
and it worked fine, but when I try and set the location to read the input
file, it doesn't work, it ends up writing "test1.txt" as a blank file, presumably
because it could not read the input file.
So my question to you is, how do I set the location in which the program will
try and find the file with the given name?