CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2011
    Posts
    1

    How do I open a text file in notepad?

    I have a program that saves the date and time into a variable and then builds a text file with that variable as the name.

    I want to open that text file in notepad from the same program right before the program closes.

    So basically i want to open a text file in notepad using a variable to designate the file name.

    Mike

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: How do I open a text file in notepad?

    ShellExecute()?

    Ah, and... Welcome to CodeGuru!
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Jan 2011
    Location
    Orange County, CA
    Posts
    82

    Re: How do I open a text file in notepad?

    or fstream...

  4. #4
    Join Date
    Jan 2011
    Location
    Orange County, CA
    Posts
    82

    Re: How do I open a text file in notepad?

    Create File:
    Code:
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    int main()
    {
        ofstream outputFile;
        char fileName[48];
        cout << "Enter File Name: ";
        cin.getline(fileName, 48);  //make sure to add the .txt
        outputFile.open(fileName);
        outputFile << ; //send stuff here
        //repeat as necessary...
        outputFile.close();
        return 0;
    }
    Read File:
    Code:
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    int main()
    {
        ifstream inFile;
        char fileName[48];
        cout << "Enter File Name: ";
        cin.getline(fileName, 48);   //make sure to add the .txt
        inFile.open(fileName);
        inFile >>  ; //read variables and stuff here
        //repeat as necessary...
        inFile.close();
        return 0;
    }
    Last edited by iiSoMeGuY 7x; May 19th, 2011 at 09:56 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured