template<> 37 Junior Poster

Do you know how to use classes yet?

It would be cleaner to model your problem using classes.

template<> 37 Junior Poster

1. Iterate through all items in the vector: for loop below
2. find item in vector that matches your item to remove: *i == who_
3. remove item from vector using iterator: _vector.erase(i)

for( TVec::iterator i=_vector.begin(); i!=_vector.end(); ++i )
        {
            if( *i == who_ )
            {
                std::cout << who_ << " is removed" << std::endl;
                _vector.erase(i); return;
            }
        }
template<> 37 Junior Poster

Comparing floating point numbers using == or != is not safe. The difference between the two numbers must be compared to some tolerance, usually the system epsilon. (see sample code below).

bool isEqual( float v1, float v2 )
{
    if( std::abs(v1-v2) < std::numeric_limits<float>::epsilon() )
    {
        return true;
    }
    
    return false;
}
ravenous commented: Helpful information +6
template<> 37 Junior Poster

Below is a example of one way to remove an item from a vector using an iterator.

class Eraser
{
public:
    Eraser()
    {
        _vector.push_back("fred");
        _vector.push_back("alice");
        _vector.push_back("billy");
    }
    bool remove(const std::string &who_)
    {
        for( TVec::iterator i=_vector.begin(); i!=_vector.end(); ++i )
        {
            if( *i == who_ )
            {
                std::cout << who_ << " is removed" << std::endl;
                _vector.erase(i);
                return true;
            }
        }

        std::cout << who_ << " is not in list" << std::endl;
        return false;
    }
    void show()
    {
        for( size_t i=0; i < _vector.size(); i++ )
        {
            std::cout << _vector[i] << std::endl;
        }
    }
private:
    typedef std::vector<std::string> TVec;
    TVec _vector;
};