Help with Log File Creation

S

subaruwrx88011

Hey,
I am trying to create log files in a different directory than where my
executable is at. I am pretty stumped. This is what I have in psuedo
code.

std::string const M_LOG_PATH = "\\data\\logs\\";
std::string m_log_filename_with_path;
std::string filename = "log.txt";

m_log_filename_with_path = M_LOG_PATH + filename;

std::fstream file;
file.open(m_log_filename_with_path.c_str());
file << "text" << std::endl;
file.close();

So....everything works but it creates the files in the same directory
as the executable and the whole file name ends up being "//data//logs//
log.txt" instead of log.txt in the //data/logs directory.

Can anyone help???
 
G

Gianni Mariani

subaruwrx88011 said:
Hey,
I am trying to create log files in a different directory than where my
executable is at. I am pretty stumped. This is what I have in psuedo
code.

std::string const M_LOG_PATH = "\\data\\logs\\";
std::string m_log_filename_with_path;
std::string filename = "log.txt";

m_log_filename_with_path = M_LOG_PATH + filename;

std::fstream file;
file.open(m_log_filename_with_path.c_str());
file << "text" << std::endl;
file.close();

So....everything works but it creates the files in the same directory
as the executable and the whole file name ends up being "//data//logs//
log.txt" instead of log.txt in the //data/logs directory.

Can anyone help???


File path names are system specific.

The "/" character works on most platforms (including recent windows
OS's) so why not try:


std::string const M_LOG_PATH = "/data/logs/"; ?


.... however, if you use the boost::file path name stuff or the Austria
C++ path name stuff, the "/" or "\" gets abstracted away and becomes OS
independant.

(The Austria filename stuff is in the netcabletv alpha).
 
S

subaruwrx88011

File path names are system specific.

The "/" character works on most platforms (including recent windows
OS's) so why not try:

std::string const M_LOG_PATH = "/data/logs/"; ?

... however, if you use the boost::file path name stuff or the Austria
C++ path name stuff, the "/" or "\" gets abstracted away and becomes OS
independant.

(The Austria filename stuff is in the netcabletv alpha).

Sorry. I forgot to tell you guys.....this is on a Debian Linux
platform!!!!
 
G

Gianni Mariani

subaruwrx88011 wrote:
....
Sorry. I forgot to tell you guys.....this is on a Debian Linux
platform!!!!

A linux system recognize "\\data\\logs" as being a simple file name -
not a directory path.
 
R

Richard James

subaruwrx88011 said:
Can anyone help???

Maybe you should read all the replies in the other thread you started
because lots of people have already answered this question of yours.

Richard James
 
J

Jim Langston

subaruwrx88011 said:
Sorry. I forgot to tell you guys.....this is on a Debian Linux
platform!!!!

In linux / is the path seperator. \ is a valid character for a file name.
So you would definately want it:
std::string const M_LOG_PATH = "/data/logs/";
which should fix your problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,201
Latest member
KourtneyBe

Latest Threads

Top