std :: vector <std :: basic_string <char>&gt; :: const_iterator'没有名为'c_str'的成员</std :: basic_string <char>

时间:2014-12-21 03:11:41

标签: c++

我有这个问题。它说:

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

请问你能帮帮我吗?

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 个答案:

答案 0 :(得分:9)

而不是

itr.c_str()

itr->c_str()

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