的大小我已經作出了串矢量取決於串矢量
vector<string> actor_;
,然後使用的push_back添加元素在它運行for循環。
我現在想要顯示它們,爲此我需要根據向量中元素的數量運行循環。對於這一點,我需要運行下面的循環:
for (int i = 0; i < (int)actor_.size; i++)
{
}
但這返回以下錯誤:
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
哦,我傻......其現在的工作。 問:爲什麼std :: size_t比unsigned int更好? – xbonez 2010-04-13 19:12:59
@詹姆斯:爲了澄清,他從來沒有'unsigned int'開頭。 (也許我正在閱讀大量的內容。)@xbonez:'size_t'是測量東西大小的標準整數類型,可能比'unsigned'大。 'size()'返回一個'size_t',所以你應該使用'size_t'來匹配。 – GManNickG 2010-04-13 19:13:37
因爲size_t將始終與size()函數的返回類型具有相同的類型,無論您正在編譯的arch/platform(x86,x86_64等)。 – 2010-04-13 19:16:39