2013-12-12 33 views
-2

我有一個類的向量:vector<qANDa> spanish;,我希望它返回長度,我使用的代碼:int a = spanish.length();,但它說,No member named 'length' in 'std::__1::vector<qANDa, std::__1::allocator<qANDa> >'。所以我基本上想知道這是爲什麼。類沒有返回長度的向量

+3

A [參考]構件(http://en.cppreference.com/w/cpp/container/vector)會告訴你如何解決這個問題。 – chris

+1

你會得到的答案是大約5秒,如果你GOOGLE了 –

+0

你甚至不需要一個參考,編譯器告訴你什麼問題是! – JBentley

回答

8

它應該是:

int a = spanish.size(); 

std::vector<T>沒有名爲length()

+0

好吧,我正在研究使用'length()'獲取字符串的長度。謝謝。 – dunnmifflsys

+2

@newbie,注意'size()'也在'string'中 – chris