Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8048861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:36:59+00:00 2026-06-05T06:36:59+00:00

Please excuse my ignorance.. i know a fair bit but am somehow still hazy

  • 0

Please excuse my ignorance.. i know a fair bit but am somehow still hazy on basics!?!Could you consider this simple example and tell me the best way to pass logmessages to ‘writeLogFile’?

void writeLogFile (ofstream *logStream_ptr) 
{  
    FILE* file;
    errno_t err;

    //will check this and put in an if statement later..
    err = fopen_s(&file, logFileName, "w+" );


    //MAIN PROB:how can I write the data passed to this function into a file??

    fwrite(logStream_ptr, sizeof(char), sizeof(logStream_ptr), file);


    fclose(file);

}

int _tmain(int argc, _TCHAR* argv[])
{

    logStream <<"someText";

    writeLogFile(&logStream); //this is not correct, but I'm not sure how to fix it

    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:37:02+00:00Added an answer on June 5, 2026 at 6:37 am

    Instead of an ofstream you need to use a FILE type.

    void writeLogFile ( FILE* file_ptr, const char* logBuffer ) 
    {  
       fwrite(logBuffer,1, sizeof(LOG_BUF_MAX_SIZE), file);
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        writeLogFile(m_pLogFile, "Output"); 
        return 0;
    }
    

    Where elsewhere

    m_pLogFile = fopen("MyLogFile.txt", "w+");
    

    Or you can use ofstreams only.

    void writeLogFile ( const char* logBuffer ) 
    {  
       m_oLogOstream << logBuffer << endl;
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        writeLogFile("Output"); 
        return 0;
    }
    

    Where elsewhere

    m_oLogOstream( "MyLogFile.txt" );
    

    Based on comment below what you seem to want to do is something like:

    void writeLogFile ( const char* output) 
    {  
        fwrite(output, 1, strlen(output), m_pFilePtr);
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        stringstream ss(stringstream::in);
        ss << "Received " << argc << " command line args\n";
        writeLogFile(m_pLogFile, ss.str().c_str() ); 
        return 0;
    }
    

    Note that you really need more error checking than I have here, as you are dealing with c-style strings and raw pointers (both to the chars and the FILE).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please excuse my ignorance, but I have come across this term owner drawn listbox.
Please excuse my ignorance when asking this question as I am still learning NHibernate
First, please excuse my ignorance in this field, I'm a programmer by trade but
this was my first dojo build so please excuse my ignorance in this matter.
Please excuse me if there are already answers to this, but I can't quite
This is my first time dabbling in NLP so please excuse my ignorance. I'm
Please excuse me if this question is really obvious but i've tried everything. I
I'm a Linq noob so please excuse my ignorance but I need to group
Excuse my ignorance but I'm having a tough time figuring this out. I'm trying
Probably really simple so please excuse my ignorance... To my knowledge, there are a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.