Sign in to follow this  
Fixxer

Need help with ifstream

Recommended Posts

This code is couting "Unknown Error" which is not good! For some reason its not opening the file or, what.
			ifstream a_file (cUsername);
			char cError[3];
			if(!a_file.is_open()){
				cError[0] = 'B';
				send(AcceptSocket,cError,strlen(cError)+1,0);
				cout<<"Error Code "<< cError << " has been sent out."<<endl;
			}
			else{
				char cFieldTwo[18];
				char cAccess[2];
				char cTemp[18];
				a_file>>cTemp;
				a_file>>cFieldTwo;
				a_file>>cAccess;
				if(cAccess[0] == '0'){
					cError[0] = 'C';
					send(AcceptSocket,cError,strlen(cError)+1,0);
					cout<<"Error Code "<< cError << " has been sent out."<<endl;
				}
				else if(cFieldTwo == cPassword){
					cError[0] = 'A';
					send(AcceptSocket,cError,strlen(cError)+1,0);
					cout<<"Error Code "<< cError << " has been sent out."<<endl;
				}
				else{
					cout<<"Unknown Error"<<endl;
				}
			}

Share this post


Link to post
Share on other sites
What are you expecting to happen? What does your file look like? What's the type of cPassword? If it's not a string type you could be running into a pointer comparison error.

Share this post


Link to post
Share on other sites
ifstream a_file (cUsername);
if (!a_file.is_open())
{
std::string error("B", 2);
send(AcceptSocket, error.c_str(), error.size(),0);
cout<<"Error Code "<< error << " has been sent out."<<endl;
}
else
{
std::string fieldTwo;
std::string access;
std::string temp;
a_file>>temp;
a_file>>fieldTwo;
a_file>>access;
if (access.empty())
{
std::string error("C", 2);
send(AcceptSocket,error.c_str(), error.size(),0);
cout<<"Error Code "<< error << " has been sent out."<<endl;
}
else if(fieldTwo == cPassword)
{
std::string error("A", 2);
send(AcceptSocket,error.c_str(), error.size(),0);
cout<<"Error Code "<< error << " has been sent out."<<endl;
}
else{
cout<<"Unknown Error"<<endl;
}
}

Enigma

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this