Problem creating file | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Problem creating file

Here I have attached two codes both intending to work with files. In the fun code example involving class carreer doesn't open any file in the directory and render the program useless, however, the other short program creates a file in the same directory! And I used the same fstream statement to declare the file opening, please can anyone put through on this? I have tried several other programs like this involving classes and still file won't create, I have been stalked for like two days on this, it's frustrating. https://code.sololearn.com/c7ZW7RIsWtr0/?ref=app https://code.sololearn.com/cPX3F5x9T33e/?ref=app

11th Aug 2018, 7:41 PM
Dauda Olushola Benedict
4 Answers
+ 2
You should close your file with “file.close()” comand after completing writing in it
11th Aug 2018, 10:15 PM
Madgod
Madgod - avatar
+ 2
try to write it at the end of every function where you open file
11th Aug 2018, 10:17 PM
Madgod
Madgod - avatar
+ 2
you are welcome
11th Aug 2018, 10:21 PM
Madgod
Madgod - avatar
+ 1
Thanks @Madgod, I have actually found a solution to the problem I am having, when I run the program, I need to first and foremost call the function including the file declaration which I have been doing otherwise, thanks!
11th Aug 2018, 10:18 PM
Dauda Olushola Benedict