Hi!

I have a problem finding a string from a register if it contains a certain character combinations and * is used to "fill" the positions of the string as we do not know the contents of.

Example:
We register "abc" and "abd".
If we only know "a" and "b" and not "c", we write ab* and all the strings that begins with "ab" should be shown.

Here is what I've done so far

void VehicleManager::findRegNr()
{
	size_t found;
	string str;
	cout<<"Enter registration-number. Type * for the letter/number you do not know"<<endl;
	cin >> str;
	 
  found=str.find_first_of('*');
  while (found!=string::npos)
  {	
	  for(int i  = 0; i <this->m_count;  i++)
	  {
		 str[found] = (m_ppVehicles[i]->getRegNr()[found]);
		 found=str.find_first_of('*',found+1);
		 
	  }
  }
  cout << str << endl;
  
  
}

It works only if it's one regnr in the register, not two or more.
My question is how I do that?

Here is when I add a vehicle if it helps you.

void VehicleManager::addCar(string brand, string age, string regNr, string price, string fuel, string size)
{
	if (this->m_count == this->m_capacity)
	{
		Vehicle **temp = new Vehicle*[this->m_capacity + 5];
		for (int i=0; i<m_capacity; i++)
		{
			temp[i] = this->m_ppVehicles[i];
		}
		delete [] this->m_ppVehicles;
		m_capacity += 5;
		this->m_ppVehicles = temp;
	}
	this->m_ppVehicles[this->m_count] = new Car();
	(this->m_ppVehicles[this->m_count])->setVehicle(brand, age, regNr, price, "", fuel, size);
	this->m_count++;
}

Grateful for answers!

so on the top one you have one variable called str, are you trying to make it s, t , r? like the abc example?

so on the top one you have one variable called str, are you trying to make it s, t , r? like the abc example?

Yes, if I understood you right!

This article has been dead for over six months. Start a new discussion instead.