Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

BCB6 project to CB2007 problem.

20 views
Skip to first unread message

Gene

unread,
Jun 26, 2008, 3:27:06 AM6/26/08
to

Hi,
I have got a compiling error saying "[BCC32 Error] switch1.cpp(40): E2034 Cannot convert 'std::_Vector_iterator<std::string,std::allocator<std::string> >' to 'std::string *'"
The code is as in below:

std::vector<std::string> StringList;
for (int i = 0; i < 10; i++) {
StringList.push_back(IntToStr(i).c_str());
}
std::vector<std::string>::iterator it=StringList.begin();
std::string* ctmp=it;
ShowMessage(ctmp->c_str());

It compiles ok in BCB6, but it is an error in C++ Builder 2007. Is it any compilation options I set wrong? Or C++ Builder 2007 is a lot stricter in grammar than BCB6? Can anyone give me help on this?

Thanks.

Gene.

Leo Siefert

unread,
Jun 26, 2008, 9:53:52 AM6/26/08
to
Gene wrote:

>Cannot convert std::_Vector_iterator<std::string> to std::string *

You are attempting to do something that is dependent upon the
implementation of the STL. a vector iterator is allowed by the
standard to be an array pointer, but it does not have to be one. There
is nothing in the standard that allows this type of conversion.

This worked in BCB6 because that used a different STL which used
pointers as vector iterators, and does not work in CB2007 because it
uses a different STL.

Since this is an implementation dependent detail, you are best to use
code that does not rely on it. Either use vector<>::iterator as your
function parameters, etc. or convert to a pointer if necessary like
this:

&*TheIterator;

In the code you posted, you can simply use the iterator itself with
pointer syntax (iterators to have * and -> implemented like pointers
do):

ShowMessage(it->c_str());

- Leo

Gene

unread,
Jun 26, 2008, 10:45:17 AM6/26/08
to

It works!

Thank you! Leo.

Gene

0 new messages