| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Thomas Mathew" |
| Date: |
31 Jan 2008 06:32:06 AM |
| Object: |
vector and wstring remove problem |
Dear All,
I am trying to remove an entity from the vector but getting many error
messages. I know it is a casting problem but I don=92t know how to fix
it.
Following is the code snippet.
bool CMdlMain::RemoveLayers()
{
bool result =3D false;
long index =3D m_oLayerListBox.Selected();
if (-1 < index) {
m_vecLayerList.erase (std::remove (m_vecLayerList.begin (),
m_vecLayerList.end (), m_vecLayerList[index]), m_vecLayerList.end
());
result =3D 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 =3D=3D(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.
Thomas
.
|
|
| User: "Alf P. Steinbach" |
|
| Title: Re: vector and wstring remove problem |
31 Jan 2008 07:29:23 AM |
|
|
* 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 don’t 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?
.
|
|
|
|
| User: "Pete Becker" |
|
| Title: Re: vector and wstring remove problem |
31 Jan 2008 08:09:41 AM |
|
|
On 2008-01-31 07:32:06 -0500, Thomas Mathew <thomasmathew50@gmail.com> said:
Dear All,
I am trying to remove an entity from the vector but getting many error
messages. I know it is a casting problem but I don’t know how to fix
it.
Following is the code snippet.
The code is far more complicated than it needs to be. If you've got an
index into a vector, you don't need to search for the corresponding
element. Just erase(begin() + index).
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
.
|
|
|
| User: "Thomas Mathew" |
|
| Title: Re: vector and wstring remove problem |
01 Feb 2008 01:08:11 AM |
|
|
Alf and Pete... Thanks for your valuable reply.
erase(begin() + index) is working fine.
Thanks Alf, Pete
Cheers, Thomas
.
|
|
|
|
|

|
Related Articles |
|
|