-
December 26th, 2012, 07:04 PM
#1
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!
-
December 26th, 2012, 10:54 PM
#2
Re: Opening Documents with C++
Originally Posted by Hazique35
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|