Hello everyone, i was just trying something when i got the error. I debugged and it says string password <Bad Ptr> and that password string have more than lets say 100000 childs of characters in it. I used the string::resize() member function but it doesnt seemed to solve the problem.

I couldn't find the solution and i have that <Bad Ptr> error a lot in my programs. What is wrong with it?

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

struct member
{
private:
	int id;
	string password;
	string name;
public:
	member()
	{
		id=0;
		password.resize(5);
		password="0000";
		name="Default";}

	member(int Id, string Password, string Name)
		:id(Id),password(Password),name(Name)
	{}

	void setId(int Id)
	{
		id=Id;}

	void setPassword(string Password)
	{
		password=Password;}
	
	void setName(string Name)
	{
		name=Name;}

	int getId()
	{
		return id;}
	
	string  getPassword()
	{
		return password;}
	
	string getName()
	{
		return name;}
};




int main()
{
	int state=1;
	int memberNum=0;
	member *members=new member[memberNum];

	while(state)
	{
		cout<<"To create a new member type 1, to view a profile type 2, to exit type 0:";
		cin>>state;
		if(state==1)
		{
			memberNum++;
			int id;
			string name;
			string password;

			
			cout<<"Enter the ID, name and password in order:";
			cin>>id>>name>>password;
			members[memberNum].setPassword(password);
			members[memberNum].setName(name);
			members[memberNum].setId(id);
		}
	}



	return 0;}

Please help me, I'm getting this error very frequently.

I found the mistake.

int memberNum=0;
member *members=new member[memberNum];

So i allocate memory for "0" member and try to do operations on the nonalocated memory.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.