I have no idea what is wrong... Anyone mind reposting on how to fix this because I suck at C++ and want to have 2 things going on at once in my passworded file-retriever. Basically I have burried a file EXTREMELY DEEP in my computer, and I made this program to retrieve it when I need it, under lock and key, so if the correct password is inputted, it opens the file, and if the wrong password is inputted, it closes that program. Just some simple stuff to keep my friends out of my "work". (And to all of you smart-asses out there, no I am not hiding porn)
Here is the code that I have so far:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
const string passwd("asshat");
string input_passwd;
cout << "Please enter your password: ";
cin >> input_passwd;
if (input_passwd == passwd)
cout << "\nPassword matches!\n";
I wanted the ifstream to work if the else was triggered.
Then possibly you meant this? Note that ( is not the same as {, and that wrapping you if and else blocks in { } is a very good idea, as it means you make it obvious what you actually meant to happen.
1 2 3 4 5 6 7 8 9 10 11
if (input_passwd == passwd)
{
cout << "\nPassword matches!\n";
}
else
{
ifstream minecraftbeach;
minecraftbeach.open; // This line is still totally wrong
}
if (minecraftbeach.is_open())
{ return 0 }