简体   繁体   中英

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

My professor sent me the code and most of it works but this part is having problems. All the methods from vector class are showing error. I don't have much experience with c++ but I need to run the code. He was running the same code and it was working just fine.

error is: class "std::vector<int, std::allocator >" has no member "begin"

almost same for all other methods as well

#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; 
}

another part of a header file is also having the same error but it's too long to post here:

        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--;
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM