簡體   English   中英

我得到 std class 向量對於我的所有向量方法沒有成員錯誤

[英]I'm getting std class vector has no member error for all my vector methods

我的教授給我發了代碼,其中大部分都可以工作,但這部分有問題。 來自向量 class 的所有方法都顯示錯誤。 我對 c++ 沒有太多經驗,但我需要運行代碼。 他正在運行相同的代碼,並且運行良好。

錯誤是: class "std::vector<int, std::allocator >" has no member "begin"

所有其他方法也幾乎相同

#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;

#include "State.h"
#include "SearchNode.h"
#include "Game.h"

vector<int> input() {
    vector<int> input;

    cout << "Input nine different numbers from 0 to 8. " << endl;
    cout << "For instance, put in 7, 0, 5, 1, 3, 8, 4, 6, 2" << endl;

    do {
        int num;
        cin >> num;
        if (num < 0 || num > 8
                || std::find(input.**begin()**, input.**end()**, num) != input.**end()**) {
            cout << "Invalid input. Try again." << endl;
            continue;
        }

        input.**push_back(num)**;

        if (input.**size()** < 9)
            cout << "Input " << (9 - input.**size()**) << " more numbers." << endl;
    } while (input.**size()** < 9);

    return input; 
}

header 文件的另一部分也有同樣的錯誤,但在這里發布太長了:

        State currentState = *initialState;
        std::priority_queue<State> searchQueue;

        std::stack<State> searchedList;

        cout << "Initial state: " << endl;
        currentState.printBoard();
        cout << "Best first search starts ... " << endl;

        searchQueue.push(currentState);

        while (!currentState.isGoalAchieved() && stepsLeft > 0
                && !searchQueue.empty()) {
            std::vector<State> stateList = nextStates(currentState);
            for (int i = 0; i < stateList.**size()**; i++) {
                if (!checkExist(searchedList, stateList[i])) {
                    searchQueue.push(stateList[i]);
                }
            }

            if (!searchQueue.empty()) {
                currentState = searchQueue.top();
                searchQueue.pop();
            }

            cout << endl;
            currentState.printBoard();
            searchedList.push(currentState);

            cout << "Number of states visited up to now " << searchedList.size()
                    << ". " << endl;

            stepsLeft--;
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM