Advertisement Jump to content
Sign in to follow this  
Fixxer

Need help with ifstream

This topic is 4888 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!