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

  • Home
  • SEARCH
  • 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 4561062
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:01:18+00:00 2026-05-21T18:01:18+00:00

I am using C++ and trying to output a file to a specific place,

  • 0

I am using C++ and trying to output a file to a specific place, a folder with a specified name in the same directory as the executable. Couldn’t find a great resource on an easy way to do this but I know it must be possible.

My example. I am saving a log file and instead of having it save to the same directory as the executable, it saves to /logs/

Thank you for your time!

Edit: I used mkdir to create a folder but how do I output to that folder. Is mkdir even a good thing to be using? I want to learn the best way to do this, not necessarily the easiest.

  • 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-05-21T18:01:19+00:00Added an answer on May 21, 2026 at 6:01 pm

    This code:

    #include <fstream>
    #include <iostream>
    
    int main()  {
        std::ofstream of( "C:\\mydir\\somewhere\\log.txt" );
        of << "hello\n";
    }
    

    will write “hello” to the file log.txt in the directory c:\mydir\somewhere, assuming the directory exists. And yes, mkdir is the right function to use. If you don’t want to hardcode the path, you can find the path & name of the executable with GetModuleFileName, and then create the path programatically from that – see How to get Current Directory? for an example.

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

Sidebar

Related Questions

I'm trying to output a sentence containing 4 variables, with their values emboldened using
I am accessing a business class using an ObjectDataSource and trying to produce output
Using ext/ldap I'm trying to add entries to an Active Directory. As long as
im trying to open a file using StreamReader and ive to set a Encoding,
I was trying to output a not null terminated char array to a file.
I'm trying to create an XML output file to import into another program. The
hi im trying to using flashVars however for some reason there not getting sent
Using Ruby I'm trying to split the following text with a Regex ~foo\~\=bar =cheese~monkey
Using extension syntax I'm trying to create a left-join using LINQ on two lists
I'm trying to leverage the using block more and more these days when I

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.