Re: vector and wstring remove problem
* Thomas Mathew:
I am trying to remove an entity from the vector but getting many error
messages. I know it is a casting problem but I dont know how to fix
it.
Following is the code snippet.
bool CMdlMain::RemoveLayers()
{
bool result = false;
long index = m_oLayerListBox.Selected();
if (-1 < index) {
m_vecLayerList.erase (std::remove (m_vecLayerList.begin (),
m_vecLayerList.end (), m_vecLayerList[index]), m_vecLayerList.end
());
result = true;
}
return result ;
}
// Following is the vector declaration
typedef std::vector<std::wstring> Vector_Layers;
Vector_Layers m_vecLayerList;
// Following is the error
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\algorithm(43) :
error C2784: 'bool __cdecl std::operator ==(const class
std::istream_iterator<_U,_E,_Tr> &,const class
std::istream_iterator<_U,_E,_Tr> &)' : could not deduce template
argument
fo r 'const class std::istream_iterator<_U,_E,_Tr> &' from 'class
std::basic_string<unsigned short,struct std::char_traits<unsigned
short>,class std::allocator<unsigned short> >'
It would be a great help if anyone could kindly help me.
The code formatting leaves much to be desired, but the following
compiles fine:
#include <vector>
#include <string>
#include <algorithm>
struct CMdlMain
{
typedef std::vector<std::wstring> Vector_Layers;
Vector_Layers m_vecLayerList;
bool RemoveLayers();
};
bool CMdlMain::RemoveLayers()
{
bool result = false;
long index = 3; //m_oLayerListBox.Selected();
if (-1 < index) {
m_vecLayerList.erase (std::remove (m_vecLayerList.begin (),
m_vecLayerList.end (), m_vecLayerList[index]), m_vecLayerList.end
());
result = true;
}
return result ;
}
int main() {}
It seems you have not posted the code that gave you problems.
Check out the FAQ's advice on how to get help with Code That Does Not
Work (this includes posting a complete, small program demonstrating the
problem).
Cheers & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?