c++ - fopen vs ofstream -
I have a strange problem that I think I have an alternative solution, but I have a basic reason on the analysis.
I am developing an application that runs on the embedded version of Ubuntu 10.04 LTS. When the application starts, it reads in a config file off of an SD card, launches some classes, launches a logger, which writes on the SD card, and then proceeds with its operation. During development, when I start manually through SSH Terminal, then it is running fine.
I have been applying to start automatically automatically when OS starts. I have a script in init.d which is just that. However, I found that no log files are being created anymore. I thought this is not a problem with the SD card because the config file is properly read at startup, but when I try to open the log file to write the FOPN, an error is thrown.
Open the // file mLogFile = fopen (filename, "wb"); If (mLogFile == NULL) {printf ("Error opening file [% d]. \ N", lnRetval); Return -1; // file could not be opened} I think this was just a permissions problem, but I do not understand that when I'm running automatically, manually Apart from this in a terminal, I do not understand why the config file is read correctly, but this file can not be opened.
I could see that the only difference is that fstreams are used to read the config file, while the logger is using C file I / O, so I call the following code directly by calling the above mentioned First (/ home / root / etc, where SD card is kept).
std :: ofstream out ("/ home / root / etc / log / testlog.log"); Outside & lt; & Lt; "I can write using fstreams. \ N"; Out.close (); It works and generates a file when Inat D is started through. Now I'm totally stumped, why does the work offstream and not fopen?
Your question does not provide enough information to answer, but the general approach to such problems Under the strace , the program should run (in both forms) and compare the sequence of created syscalls. It should immediately reveal what is happening in different ways. I suspect you only have the content of filename invalid ...
Comments
Post a Comment