Need help with ifstream

Started by
1 comment, last by Enigma 18 years, 7 months ago
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;
				}
			}

Advertisement
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.
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

This topic is closed to new replies.

Advertisement