By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,446 Members | 1,317 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,446 IT Pros & Developers. It's quick & easy.

Opening files in a C++ Readfile program from different Directories

P: 6
Hi all,
I am wondering how do I read files from a different directory while using ofstream function. I am new to C++ and I will need to read file from the path given. What are the solutions available? Many thanks in advance.
Dec 22 '06 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 8,916
include the complete path to the file when you open it, i.e. rather than "file.txt" use "\\<MyDirectory>\\<MySubDirectory>\\file.txt"

Note the use of double \ because in a C++ string or character constant \ is the escape character.
Dec 22 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.