File Openings

Pages: 123
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");
}

Well, you need to escape your slashes, or use forward slashes instead.
what do u mean escape my slashes?
ur talking about the ones in the path directory right?
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
oh ok and then could somebody compile and run this program to see if there are any errors? because my compiler wont work atm?
wtf?
what?
i think your priority should be fixing your compiler rather than getting other people to run your code for you.
The problem is that on windows 8 Dev c++ wont work :/
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
Well no,
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.
DOes path to the password exist? Does that file exist? Does your program have enough permissions to open that file?
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?
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");
}
]
exclude the brackets sry about that
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?
ok and yes
how do i attach a file?
Pages: 123