I am trying to build a Log File in c++... Can anyone tell how multiple variables such as a string,integer be written onto the file... the write to the file part of code is written in a different function present in a different file (ex. log_file.h) linked to the main file..
example:
for(int i=0;i<3;i++)
{....}
I want to write each iteration value of i to the log file...
I can do this by passing "value of i"
-->in a string and "i"
--> as an integer... but this will not work for all functions..
If you want to do it in a C++ way then I think you should use streams and templates. Like the following:
As you see the logger depends on
std::ofstream
. So if you need to log some unsupported type you just need to make an overload for it. Like this:And then use it in
main
: