std::vector >::::const_iterator '没有成员名为' c_str '

时间:2022-07-20 22:26:04

i have problem with this. It says this:

我对此有异议。它说:

‘std::vector<std::basic_string<char> >::const_iterator’ has no member named ‘c_str’

Could you help me, please ?

你能帮我一下吗?

for ( ObjectMgr::WayContainer::const_iterator itr = Ways.begin(); itr != Ways.end(); ++itr )
{

char *cstr = new char[itr.length() + 1];
strcpy(cstr, itr.c_str());

if ( !stricmp(cstr, wayss) )
{
return;
}

delete [] cstr;
}

1 个解决方案

#1


7  

Instead of

而不是

itr.c_str()

write

itr->c_str()

Because c_str is a member not of the iterator but of the std::string it refers to. In the same vein, replace itr.length() with itr->length().

因为c_str不是迭代器的成员,而是std::string的成员。同样,将itr.length()替换为itr->长度()。

#1


7  

Instead of

而不是

itr.c_str()

write

itr->c_str()

Because c_str is a member not of the iterator but of the std::string it refers to. In the same vein, replace itr.length() with itr->length().

因为c_str不是迭代器的成员,而是std::string的成员。同样,将itr.length()替换为itr->长度()。