HI


Friends i have create this simple code in visual C++

#include<iostream>

int main()

{
	std::cout<<"Hello World!!"<<std::endl;
	system ("PAUSE");
	return 0;
}

can anyone help me to write log file on base of this please

Recommended Answers

All 5 Replies

This program does not need any log keeping.Because it's very simple.

For a example secnario.
When a user login you can log that to a file. like in this format.
"User:<username> had logged in time:<time> with priviledges:<granted priviledges>\n"

like that.

When you want to debug your application using log files, then there are secnarios
like this. For a example when you opening a file,you can write it to log file.
If the file was not found or error occurred during the file open you can write that
also to the logfile.
or when you initialize a module,say for a example MAPI session, you could write that
to a log file.
Even when you allocating a large memory block you could write that too.

So build your secnario for log keeping.

ok but this is just the example which i am writing and second thing can you tell where i have to write this log file in .txt files or i can write in visual c++ and please help me with log syntax please......

so sounds like you are inside microsoft windows.In the Linux operating system
there is a special place for the log file that is /var/log/ ,

In the windows environment it's local to the each software.so inside your application
folder you can have logs, for a example for the error log.
error.log
For runtime log.
runtime.log

etc.
Or you can create a espical folder called logs and inside that folder you
can write your logs.
./logs/runtime.log
./logs/error.log
./logs/memory.log
./logs/users.log
etc.
Looking at how the linux OS keeping logs help you to take a good idea how you
going to do this.for a example if your project does contain a module called
http_downloader then you can save it's logs inside ,
./logs/http_downloder/error.log
./logs/http_downloader/network.log
etc.

Please note that '.' means the current working folder.

to write logs,it not need to be .txt usually it ends with .log but not necessary.
you can open the files using the STL(standard template library) file I/O functions
and you can write to the files.
Here is a quick tutorial how to user STL to open and do file I/O.
http://www.cplusplus.com/doc/tutorial/files/

don't forget to close the files when you exit/terminate the application.
Practice to flush the streambuf to the real physical disks after you write
something to the log files.

// basic file operations
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
}

this is one code when i am running its not giving me any out put help plz

// basic file operations
   
      #include <iostream>
   
      #include <fstream>
   
      using namespace std;
   
      int main ()
 {
   
      ofstream myfile;
  
      myfile.open ("example.txt");
   
      myfile << "Writing this to a file.\n";
  
      myfile.close();
  
      return 0;
  
      }

hey friends can you tell me how do i call this log file into another function please we have stuck in this please

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.