Here is my code, how do i create a file in the sub directory contacts? Every time the file is created, it appears in the same directory as my program.
int main(){
ofstream myfile("\\contacts");
myfile.open ("a");
myfile.close();
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Specify the full path in the constructor:
The posted code attempts to create a file called
"\\contacts"and then another file called"a".Note:
ofstreamwill not create intermediate directories:"contacts"must exist prior to the use of theofstream.ofstreamso it is unnecessary to explicitly callmyfile.close().