954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Assertion Failed

Can anyone tell what cause the run time "Debug Assertion Failed!" error message? it has expression: sizeInBytes>count

int main()
{
int choice;        // for menu choice
string option;		// for repeat going back to menu option
Name name[300];
		
int i=0;          // count 

do{
	cout<<"Welcome!"<<endl;
	cout<<"1.Get the data"<<endl;
	cout<<"2.See the data"<<endl;
	cout<<"   1.forward"<<endl;
	cout<<"   2.backward"<<endl;
	cout<<"3.Add someone"<<endl;
	cout<<"4.Delete someone"<<endl;		
        cout<<"5.Edit an entry"<<endl;
	cout<<"6.Search for someone"<<endl;
	cout<<"   1.ID"<<endl;
	cout<<"   2.last name"<<endl;
	cout<<"7.Sort the data"<<endl
	cout<<"   1.ID"<<endl;
	cout<<"   2.last name"<<endl;
	cout<<"8.Information about the file"<<endl;
	cout<<"9.Save"<<endl;
	cout<<"10.exit"<<endl;
				
	cin>>choice;
	cout<<endl;

	switch(choice)
	{
	case 1:
	{
		int id;
		string lastName, firstName, phone;
		double amt;
		
		ifstream reader;
		reader.open("names.txt");

						             while(reader>>id>>lastName>>firstName>>phone>>amt)
		{
			
		name[i].set(id, lastName, firstName, phone, amt);
		i++;
		}
		reader.close();
		cout<<"Data read."<<endl;
		break;
		}
	case 2:
	{
		int secPick;
		cout<<"1.forward    2.backward"<<endl;
	        cin>>secPick;
		if(secPick==1)
		{
		showlist(name, i);
		cout<<endl;
	}

		else if(secPick==2)
		{
		showlistBackward(name, i);
		cout<<endl;
		}

		else
		{
		cout<<"You have entered a wrong option"<<endl;
		exit(1);
		}
		break;
		}
		case 3:
				
		addName();
		break;

		case 9:
		save(name, i);
		//cout<<"Sorry, not yet implemented.";
		break;

	case 10:
		exit(0);

		default:
		cout<<"Sorry, this input is not an option";
		exit(1);
				
		}
		cout<<"Do you want to go back to the main menu? (Enter yes or no)";
		cin>>option;
		}while(option=="yes" || option=="Yes");

		return 0;
	}
k2k
Posting Whiz
352 posts since Nov 2007
Reputation Points: 15
Solved Threads: 1
 

>Can anyone tell what cause the run time "Debug Assertion Failed!" error message?
Usually it means you caused a library function to break by doing something that it's assuming won't happen. This can also happen in your own code if you use assertions (which is rare, sadly). Step through your code to find out where it's throwing the error and you'll be well on your way to figuring out what's wrong.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Build your program in debug mode, and run in debug mode, you will find exact line which is causing assertion failure.

ithelp
Nearly a Posting Maven
Banned
2,230 posts since May 2006
Reputation Points: 769
Solved Threads: 128
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You