Try this code:
#include <iostream>
#include <fstream>
#include<string>
#include<conio.h>
using namespace std;
int main() {
string username, password, usernameFromFile;
char filename[] = "myfile.txt";
ofstream Login(filename, ios::app);
ifstream ViewLogin(filename);
cout<<"Enter username: ";
getline(cin, username);
getline(ViewLogin, usernameFromFile);
while(username == usernameFromFile)
{
cout<<"\nUsername already exist!! Enter username: ";
cin>>username;
}
Login<<username;
cout<<"Enter password: ";
getline(cin, password);
Login<<password<<"\n";
Login.close();
return 0;
getch();
}
Cheers,
jmrosendal