简体   繁体   English

我得到 std class 向量对于我的所有向量方法没有成员错误

[英]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.来自向量 class 的所有方法都显示错误。 I don't have much experience with c++ but I need to run the code.我对 c++ 没有太多经验,但我需要运行代码。 He was running the same code and it was working just fine.他正在运行相同的代码,并且运行良好。

error is: class "std::vector<int, std::allocator >" has no member "begin"错误是: 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: 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