2013-11-24 86 views
-2

我使用Qt的創造者和Xcode的4.63(OSX MAV)沒有成員

我只是叫.set(....)並得到了以下錯誤

no member named 'set' in 'std::vector<int, std::allocator<int> >

似乎就像lib有些問題,因爲我是QT創建者的新手,我仍然不知道如何使它正確。 (我是新來的C++)

#include <cctype> 
#include <cmath> 
#include <fstream> 
#include <iostream> 
#include <sstream> 
#include <string> 
#include "console.h" 
#include "filelib.h" 
#include "grid.h" 
#include "gwindow.h" 
#include "simpio.h" 
#include "vector.h" 
using namespace std; 

int main() { 
    vector<int> myVector(10,0); 

    fstream mystream; 
    string getStream; 

    while(getline(mystream,getStream)) { 
     getline(mystream,getStream); 
     if(stringToInteger(getStream)>=0 && stringToInteger(getStream)<=9) { 
      myVector.set(0,(myVector[0]+1)) 
     }; 
    } 
    return 0; 
}; 
+8

的錯誤是很清楚的:如果你想改變一個值,你可以使用[]操作符。該功能不存在。如果你調用'myVector.kerfluffle()',你會遇到同樣的問題。' –

+0

錯誤很明顯:'std :: vector'沒有名爲'set'的方法。 – juanchopanza

+0

注意:你在關閉大括號中有不必要的分號'};' – Hulk

回答

2

STL中向量不存在「set」方法。

myVector[0] = myVector[0] + 1; 

甚至

myVector[0]++; 
+3

'assign'有些不同 – Paranaix

+0

..基於你對海報試圖用不存在函數實現什麼的知識? :) – fpw

+2

它沒關係,分配做一些完全不同的事情,你發佈的代碼 – Paranaix