【问题标题】:std::vector<std::basic_string<char> >::const_iterator’ has no member named ‘c_str’std::vector<std::basic_string<char> >::const_iterator' 没有名为“c_str”的成员
【发布时间】:2014-12-21 03:11:40
【问题描述】:

我有这个问题。它是这样说的:

‘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;
}

【问题讨论】:

  • 我看不出为什么你必须复制字符串而不是直接将itr-&gt;c_str() 传递给比较函数。

标签: c++


【解决方案1】:

代替

itr.c_str()

itr->c_str()

因为c_str 不是迭代器的成员,而是它所指的std::string 的成员。同样,将itr.length() 替换为itr-&gt;length()

【讨论】:

    猜你喜欢
    • 2015-11-14
    • 2013-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多