File Openings

Pages: 123
Dec 28, 2014 at 5:48pm
Hey guys, so I need to create a program that will prompt the user for an input, then it will save their input to a file and then it will prompt the user to input "Open" and then the file containing their first input, will open up and show their input.

Any help at all will be much appreciated!
Dec 28, 2014 at 7:00pm
Dec 31, 2014 at 5:51pm
I read it and I think I need the one with the: Reading from a file. But can someone please explain it to me so I understand it? like what each line does?
Jan 1, 2015 at 7:12pm
Dude it's all there in that link :)
Jan 1, 2015 at 8:14pm
Jan 2, 2015 at 5:37pm
Here's what you can do:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main(){

	string input;

	cout << "Enter the input: ";
	getline(cin, input, '\n');
	cout << endl;

	// Create a new file named "output" and write the input to it
	ofstream out("output.txt");
	out << input;
	out.close();

	cout << "Enter 'Open' to display your input from file: ";
	getline(cin, input, '\n');
	cout << endl;


	if (input == "Open" || input == "open"){
		string inputRead;

		// Open "output.txt" file and read the first line
		ifstream in("output.txt");
		getline(in, inputRead, '\n');

		cout << endl << inputRead << endl;

	}

	system("PAUSE");
}
Jan 8, 2015 at 9:13pm
So wait, do I need to create an output.txt BEFORE i run this program, OR when I run this program, will it create a text file called output.txt and write in that immediately?
Jan 10, 2015 at 4:46pm
Ok i ran ur program. it works great just one thing. i dont want it to display whats inside the txt file in the cmd. I want the text file to literally open up when the user inputs Open, with their password in it. How do i do tht?
Jan 11, 2015 at 7:38pm
From what I know, that's not possible.

To answer your previous question, the file will be created automatically. If it already exists, its content will be overwritten. If you don't want to overwrite the contents, use this:

ofstream out("output.txt", ios::app);
Last edited on Jan 11, 2015 at 7:41pm
Jan 11, 2015 at 11:30pm
I want the text file to literally open up when the user inputs Open
If you are using Windows:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb776886%28v=vs.85%29.aspx
Jan 12, 2015 at 1:16pm
I looked at that link and I don't really understand it. Like what header files are involved and what is the syntax?
Jan 12, 2015 at 1:33pm
what header files are involved and what is the syntax?

http://puu.sh/epLfJ/a07b709b93.png
Hm. It looks like I supposed to use ShellExecute to do the task... Hey, it is a link!
http://puu.sh/epLjX/d19fb47611.png
And it have syntax description. And extensive description of different parameters. And required headers (and for almost all windows API you can just include windows.h).

And if for some reason you still not understand, this will open text file "D:/sample.txt" in default text editor:
ShellExecute(NULL, "open", "D:/sample.txt", NULL, NULL, 0);
Jan 13, 2015 at 9:04pm
Ok, now it makes sense! The thing that confused me was the ShellExecute. I just wasn't sure how to implement that! xD
Jan 13, 2015 at 9:05pm
And so i dont need any new specific header files in order to accomplish the ShellExecute function?
Jan 13, 2015 at 10:13pm
MiiNiPaa wrote:
Hey, it is a link!
http://puu.sh/epLjX/d19fb47611.png
And it have syntax description. And extensive description of different parameters. And required headers (and for almost all windows API you can just include windows.h).
Jan 21, 2015 at 6:03pm
And if my file is in my C drive, then rather than putting a D: I should put a C:?
Jan 21, 2015 at 6:15pm
Yes, you put complete path to your file here.
Jan 21, 2015 at 6:45pm
Oh, so not just C:\Password_File.txt?
So I have to type: C:\Users\battl_000\Desktop\PASSWORD_FILE.txt
Jan 22, 2015 at 8:01pm
?
Jan 22, 2015 at 8:20pm
Yes, you have to type it exactly like you would type it in, say, cmd.exe to open it.
Pages: 123