Opening Documents with C++
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Opening Documents with C++

  1. #1
    Join Date
    Dec 2012
    Posts
    1

    Angry Opening Documents with C++

    OK. This is my first post on this site, and I consider myself quite a beginner in C++. I want to know how to open up a
    document using C++. Ive tried many times, but it just comes up with a blank console which goes away when I press
    enter. I suspect the problem is that I am making a cionsole application instead of some other application that I sgould be using. (I am using Miscrosoft Visual C++ 2010) I really do not know why this is not working. Is it because I am
    trying to open a document that is not allowed to be opened???? (Im an adminstator on my computer so that is
    proobably not it.) Anyway here is the code that I wrote:


    Code:
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    int main()
    {
    	ofstream wordDocument;
    	
    	wordDocument.open("C:\\Users\\Haziqu\\Documents\\STUDYING STUFF\\BUSINESS\\adding value #1.txt.txt");
    
    	cin.get();
    	return 0;
    }
    Thanks!

  2. #2
    Join Date
    Apr 1999
    Posts
    27,446

    Re: Opening Documents with C++

    Quote Originally Posted by Hazique35 View Post
    OK. This is my first post on this site, and I consider myself quite a beginner in C++. I want to know how to open up a
    document using C++. Ive tried many times, but it just comes up with a blank console which goes away when I press
    enter.
    The program does that because that is what you wrote.

    All your program does is

    1) open a new output file (the wordDocument.open() function),
    2) wait for a key to be pressed using the cin.get()
    3) returns 0 from main(), ending the program.

    What else did you expect the program to do? If you wanted to open an existing file for input, then the class to use is ifstream, not ofstream. Otherwise, the program is behaving exactly as you wrote it.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; December 26th, 2012 at 10:57 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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center