Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Opening a file to write to

Opening a file to write to

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionsysadmin
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NewHSKid
    wrote on last edited by
    #1

    Hi, Its me again, looking for more help. I'm still working on the same project as last time i was on here (sending information through the ethernet) ;P The app has a main window that just displays the menu bar, and 3 dialogs. My app makes a message using the 3 different dialog windows. Each one will add a value to a number that i have when a "create" button is pressed (each one has their own button). Here is where I am having the problem. Sometimes i need to send it to the server, but some other times i need to save it to a file. So the user can make a entire file of different messages. I am using the call

    CFileDialog InputFile(TRUE, "*.txt", "Message, NULL, "*.txt", NULL);
    

    to make the window for the user to enter the name of the text file. My question is: 1)When do i create, open, close the file that I am going to be writing to? 2)Where do i do all the "ofstream out" stuff? When i click the "create" button on the 3 dialogs that make the message? Thanks for helping me. (I'm new to coding, i'm 15. Can you please keep the answer simple and with examples if you have time. If not just explain as you normally would) Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

    P 1 Reply Last reply
    0
    • N NewHSKid

      Hi, Its me again, looking for more help. I'm still working on the same project as last time i was on here (sending information through the ethernet) ;P The app has a main window that just displays the menu bar, and 3 dialogs. My app makes a message using the 3 different dialog windows. Each one will add a value to a number that i have when a "create" button is pressed (each one has their own button). Here is where I am having the problem. Sometimes i need to send it to the server, but some other times i need to save it to a file. So the user can make a entire file of different messages. I am using the call

      CFileDialog InputFile(TRUE, "*.txt", "Message, NULL, "*.txt", NULL);
      

      to make the window for the user to enter the name of the text file. My question is: 1)When do i create, open, close the file that I am going to be writing to? 2)Where do i do all the "ofstream out" stuff? When i click the "create" button on the 3 dialogs that make the message? Thanks for helping me. (I'm new to coding, i'm 15. Can you please keep the answer simple and with examples if you have time. If not just explain as you normally would) Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

      P Offline
      P Offline
      PremL
      wrote on last edited by
      #2

      The CFileDialog does not create the file, nor does it open it. All the dialog does is give you a standard interface for choosing a file. You have to create the file afterwards. First you construct the dialog. When you call DoModal(), the dialog appears. When the user clicks open, the dialog returns IDOK. At this point your code can access the path to the file selected by the user using the GetPathName() member function. CFileDialog InputDlg(TRUE, "*.txt", "Message.txt", NULL, "Text Files (*.txt)|*.txt", NULL); if(IDOK==InputDlg.DoModal()){ CString filename = InputDlg.GetPathName(); //create the file here } I suggest you have a look at the documentation for CFileDialog on the MSDN. It will tell you about some other member functions you can use and also about a little error with the file filter you had in the constructor. Lorenz Prem Microsoft Corporation

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups