Click here to Skip to main content
15,906,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include <iostream>
#include <fstream>
#include<string>
#include<conio.h>

using namespace std;

int main() {
    string username, password;
    bool    char filename[] = "myfile.txt";

    ofstream Login(filename, ios::app);

    cout<<"Enter username: ";
    getline(cin, username);

/*---the error start here(could not convert `username' to `bool' ) */
      while(username entered by user == username found in file)
{
          cout<<"Username already exist!! Enter username: ";
          getline(cin, username);
      }


    Login<<username<< " ";
    cout<<"Enter password: ";
    getline(cin, password);
    Login<<password<<"\n";

    Login.close();
    return 0;
    getch();
}
Posted
Updated 11-Jan-12 18:21pm
v2

I think the line
bool char filename[] = "myfile.txt";

must be
char filename[] = "myfile.txt";
only
 
Share this answer
 
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
 
Share this answer
 
v3
Comments
reikuxian 12-Jan-12 0:44am    
thankyou :)
agent_suwastica 12-Jan-12 0:45am    
welcome =)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900