File Openings

Pages: 123
Jan 22, 2015 at 8:29pm
Ok so will this program work do you think?

#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
using namespace std;
int main()
{
system ("Color 2");
string input;
cout << "Enter the input: ";
getline(cin, input, '\n');
cout << endl;

// Create a new file named "Password_file.txt" and write the input to it
ofstream out("Password_File.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 "Password_File.txt" file and read the first line
ShellExecute(NULL, "open", "C:\Users\battl_000\Desktop\PASSWORD_FILE.txt", NULL, NULL, 0);

cout << endl << inputRead << endl;

}

system("PAUSE");
}

Jan 22, 2015 at 8:37pm
Well, you need to escape your slashes, or use forward slashes instead.
Jan 23, 2015 at 3:16pm
what do u mean escape my slashes?
ur talking about the ones in the path directory right?
Jan 23, 2015 at 3:18pm
yea he/she mean this:
"C:\Users\battl_000\Desktop\PASSWORD_FILE.txt"

should be this
"C:\\Users\\battl_000\\Desktop\\PASSWORD_FILE.txt"

http://en.wikipedia.org/wiki/Escape_sequences_in_C

or use forward slashes instead
Last edited on Jan 23, 2015 at 3:22pm
Jan 23, 2015 at 3:40pm
oh ok and then could somebody compile and run this program to see if there are any errors? because my compiler wont work atm?
Jan 23, 2015 at 3:52pm
wtf?
Jan 23, 2015 at 3:57pm
what?
Jan 23, 2015 at 4:05pm
i think your priority should be fixing your compiler rather than getting other people to run your code for you.
Jan 23, 2015 at 4:19pm
The problem is that on windows 8 Dev c++ wont work :/
Jan 23, 2015 at 5:39pm
Get visual studio 2013 express or something like that.
Were you planning on asking people on this forum to keep compiling your code for you for the foreseeable future?
Last edited on Jan 23, 2015 at 5:40pm
Jan 24, 2015 at 4:37pm
Well no,
Jan 26, 2015 at 2:26pm
Ok, so I just ran the program, and It DIDNT open the file. I even did the 2 slashes, so why doesnt it open the file?! It does save the password to the file but does not open it.
Jan 26, 2015 at 2:44pm
DOes path to the password exist? Does that file exist? Does your program have enough permissions to open that file?
Jan 29, 2015 at 4:48pm
The path exists, and the file exists. I'm not quite sure what you mean when you say "does your program have enough permissions to open that file?" After all its juts a .txt file, so it should require any admin privileges?
Jan 29, 2015 at 4:55pm
This is the code I have so far:
[#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
using namespace std;
int main()
{
system ("Color 2");
string input;
cout << "Enter the input: ";
getline(cin, input, '\n');
cout << endl;

// Create a new file named "Password_file.txt" and write the input to it
ofstream out("Password_File.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 "Password_File.txt" file and read the first line
ShellExecute(NULL, "open", "C:\\Users\\battl_000\\Desktop\\PASSWORD_FILE.txt", NULL, NULL, 0);

cout << endl << inputRead << endl;

}

system("PAUSE");
}
]
Jan 29, 2015 at 4:55pm
exclude the brackets sry about that
Jan 29, 2015 at 5:21pm
Your code works fine.
I want a screenshot proving file existence in that directory.
Something like that: http://puu.sh/fc5ch/b59a2ccf5d.png
Do you really launch your program from desktop?
Jan 29, 2015 at 8:03pm
ok and yes
Jan 29, 2015 at 8:04pm
how do i attach a file?
Jan 29, 2015 at 8:18pm
Pages: 123