not declared in this scope

For some reason I can not remedy the one error. Please advise. Thanks.


#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <sstream>

using namespace std;
// TESTING FILE STREAM OPERATOR


int main()
{
std::ifstream in("ballots.txt");
std::stringstream buffer;
buffer << in.rdbuf();
std::string input = buffer.str();
std::cout << input << std::endl << std::endl;


string votes[uniqueVotes];
int currentID;
int YN; //yes or no
string ID[uniqueVotes]; //the first vote a member casts
int ID; //HogwartID number
char ADM1, ADM2, ADM3, ADM4, ADM5, ADM6, ADM7, ADM8, ADM9, ADM10; //vote on amendments
string vote; //vote for captain

ifstream fileReader; //open file for reading
fileReader.open("ballots.txt");
if (fileReader.fail())
{
cout << "The ballots failed to open with code: " << fileReader.failbit;
}
else
{
do
{
fileReader >> ID;
cout << "Id:" << ID;
fileReader >> ADM1;
fileReader >> ADM2;
fileReader >> ADM3;
fileReader >> ADM4;
fileReader >> ADM5;
fileReader >> ADM6;
fileReader >> ADM7;
fileReader >> ADM8;
fileReader >> ADM9;
fileReader >> ADM10;
cout << " Amendments 1 - 10: " << ADM1 << ADM2 << ADM3 << ADM4 << ADM5 << ADM6 << ADM7 << ADM8 << ADM9 << ADM10;
getline(fileReader,vote);
//fileReader >> vote;
cout << " the votee: " << vote << endl;


//fileReader.ignore(30,'\n');
} while(!fileReader.eof());

}

fileReader.close();

if (ID[uniqueVotes] != currentID)

{

//if this is a new ID, fill next row of parallel arrays

for (int j = 0; j < 10; j++){

fileReader >> YN[uniqueVotes][j];

}

getline(fileReader,vote[uniqueVotes]);



currentID = ID[uniqueVotes]; //set new current ID



uniqueVotes++; //new uniqueVote ID was found

}
Where is uniqueVotes declared?
I guess my question is how should I declare it.
Also, why are you using the fully-qualified name for
1
2
3
4
5
std::ifstream in("ballots.txt");
std::stringstream buffer;
buffer << in.rdbuf();
std::string input = buffer.str();
std::cout << input << std::endl << std::endl;

when you've already called the using declaration?
It has to be declared as a constant because you are using it to define the size of an array.

 
const int uniqueVotes = 5;

But that's a problem because you are modifying this variable in your program. Maybe you want to use a different variables for setting the size of the array and for indexing the array.

Consider using a vector instead of an array. A vector can be used similar to an array but it has the advantage that it can be resized.

http://www.cplusplus.com/reference/vector/vector/
Last edited on
Topic archived. No new replies allowed.