【发布时间】:2015-05-21 15:45:49
【问题描述】:
如何获取第一个字符或如何在遍历该向量时从字符串向量中的字符串按索引获取字符。 这是我的代码:
vector<string>::iterator i=vec.begin();
while(i!=vec.end()){
if(i[0]==ch)
cout<<"output";
}
它给出了错误:
'operator==' 不匹配(操作数类型为 'std::basic_string' 和 'char')|
【问题讨论】:
-
而不是您的
while循环使用范围基于for,例如for( const string& s : vec ) { if( s.length() > 0 && s[0] == ch )
标签: c++ string c++11 vector stl