我做了一个字符串向量
vector<string> actor_;
Run Code Online (Sandbox Code Playgroud)
然后使用push_back在其中添加元素.
我现在想要显示所有这些,我需要根据向量中的元素数运行循环.为此,我需要运行以下循环:
for (int i = 0; i < (int)actor_.size; i++)
{
}
Run Code Online (Sandbox Code Playgroud)
但是这会返回以下错误:
error C2440: 'type cast' : cannot convert from 'unsigned int (__thiscall std::vector<_Ty>::* )(void) const' to 'int'
1> with
1> [
1> _Ty=std::string
1> ]
1> There is no context in which this conversion is possible
Run Code Online (Sandbox Code Playgroud)
size是一个成员函数; 你的意思是:
for (unsigned int i = 0; i < actor_.size(); i++) { }
Run Code Online (Sandbox Code Playgroud)
(这是一个好主意,std::size_t而不是使用unsigned int)