If the words "email" "username" and "password" are written in the text document, start by removing them so it looks like this.
email@email.com
user123
1234
Then if you put the text file in the same folder as the source, this basic program should be a start.
#include <iostream>
#include <fstream>
#include <string>
using std::cout;
using std::cin;
using std::ifstream;
using std::getline;
using std::endl;
using std::string;
int main()
{
ifstream input("info.txt"); //open the text document
string line;
//int lineCounter;
string mail;
string password;
string username;
cout << "Enter your mail: " << endl;
cin >> mail;
cout << "Enter your password: " << endl;
cin >> password;
int compareResult;
if (input.is_open())
{
while(getline (input,line)) //loop through input file line by line
{
if (line.length() > 0) //skip empty lines
{
//lineCounter++; //keeps track of what line you're at
compareResult = line.compare(mail); //compare each line of the document with the entered mail
if (compareResult == 0) //if match..
{
getline (input,line); //get next line (username)
username = line; //store username in a variable
getline (input,line); //get next line (password)
compareResult = line.compare(password); //compare password with entered password
if (compareResult == 0) //if match..
{
cout << "Logged in as " << username << endl;
}
}
}
}
input.close();
}
return 0;
}
Just change the code to match the name of your textfile or vice versa, just tried it and got logged in as user123.
Next time you need to find the answer to something similar, search for something like "searching text file for a particular string c++"
I haven't done anything in c++ in ages, but this question was the first I saw after signing up so I felt compelled,
THANK YOU!