in case it's not clear :
string foo[ ]
is different from
char foo[]
the former is an array of string, and a string is an array of char while the latter is just an array of char,
in the former, you can store multiple words and access it using
foo[ index ]
while in
char foo[]
you can only store a word, and if you access it using
foo[ index ]
, what you will access is a single character
1 2 3 4 5 6 7 8 9
|
string foo // a string or array of char, logically similar to char foo[]
char foo[] // logically equal to the above
string foo[] // this is not equal to the other 2 above, this can be think of as an array of array of char
//--
char* foo[]
char foo[][]
char** foo
// are all logically equivalent to string foo[]
|
Edit BTW, in your performwhileloop() function, you don't have any statement that increments i, and also you redefine
candidate
and
vote
w/c is not needed, so your function should be something like :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
void performwhileloop(
ifstream& input,
ofstream& output,
string candidate[],
int size, int vote[],int size2
)
{
int i=0;
while ( input >> candidate[ i ] >> vote[ i ] || i < size )
{
output << candidate[ i ] << " " << vote[ i ]; // i think you are missing a newline
i++;
}
}
|
and also, just like what
Parasin said, you should give a function a reasonable and straightforward name, something like writeInfoToFile(), writeVotesToFile() etc..