"VectorName" was not declared in this scope..?

Closed, pasting the error here helped me notice the issue. I missed one lowercase letter. And now I understand what the error was suggesting.. Looked like it was suggesting exactly what I had.. Totally didn't see the case difference even though I was checking for it...

Please Note: This is for a homework assignment, however, the due date was at least a week ago. I'm just doing this for the learning aspect.

I've made a lot of progress today for the assignment but am stuck on this issue and I haven't been able to figure it out for quite a while now.

The issue is that I get these errors when compiling:
1
2
3
4
5
6
7
8
9
PATH $ g++ -std=c++14 Main.cpp MainFunctions.cpp Player.cpp
MainFunctions.cpp: In function ‘void printAPlayersData(std::vector<Player>&)’:
MainFunctions.cpp:198:23: error: ‘playersVec’ was not declared in this scope
         checkedName = playersVec[i].getPName();
                       ^~~~~~~~~~
MainFunctions.cpp:198:23: note: suggested alternative: ‘PlayersVec’
         checkedName = playersVec[i].getPName();
                       ^~~~~~~~~~
                       PlayersVec


When is very confusing because I use the same code in another function above it and it works perfectly fine. I've checked the parameters between the two (for differences), the details and cases of letters. I have no clue what's wrong.

Here are the 2 functions I'm referring to:
(In MainFunctions.cpp)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Will display all data:
// ---> Working Function <---
void printAllData(std::vector<Player> &PlayersVec) {
    std::cout << "\n";
    unsigned int vectorSize = PlayersVec.size();
    for (unsigned int i = 0; i < vectorSize; i++) {
        std::cout << "Player #" << i+1 << ": \n";
        std::cout << PlayersVec[i].getPName() << '\n'
                  << PlayersVec[i].getTName() << '\n'
                  << PlayersVec[i].getPnts() << '\n'
                  << PlayersVec[i].getRbnds() << '\n'
                  << PlayersVec[i].getAssts() << '\n';
        std::cout << std::setfill('-') << std::setw(69) << "\n";
    }
    std::cout << "\n";
}

// ---> Not Working Function <---
void printAPlayersData(std::vector<Player> &PlayersVec) {
    std::string aPlayer = "", checkedName = "";

    // Asks for input
    std::cout << "Which player would you like to print data for?\n";
    std::cout << "Type their full name (CaSE-SenSiTiVE): ";
    std::cin.ignore(1000, '\n');
    std::getline(std::cin, aPlayer);

    unsigned int vectorSize = PlayersVec.size();
    
    // Finds the name in vector (if it is in vector)
    for (unsigned int i = 0; i < vectorSize; i++) {
        checkedName = playersVec[i].getPName();

        if (aPlayer == checkedName) {
            std::cout << std::setfill('-') << std::setw(69) << '\n';
            std::cout << "Player Data:\n";
            std::cout << PlayersVec[i].getPName() << '\n'
                    << PlayersVec[i].getTName() << '\n'
                    << PlayersVec[i].getPnts() << '\n'
                    << PlayersVec[i].getRbnds() << '\n'
                    << PlayersVec[i].getAssts() << '\n';
            std::cout << '\n';
        }
        // If the player name wasn't found in the vector at all:
        else if (i == vectorSize) {
            std::cout << "The player name you entered was not found in the vector. Did you use proper CAseS?\n";
        }
    }
}


Please Note: Error line numbers may be a bit off because I removed some comments.
Main.cpp: ...
MainFunctions.cpp: ...
Player.h: ...
Player.cpp: ...
Players.txt: ...

Help would be greatly appreciated. Thank you!
Last edited on
Closed.
... Missed one case letter. :P
Topic archived. No new replies allowed.