When I read in a .txt file with 5 words in it from my program and put into an array with 20 spaces the last word in my file fills up the last 16 places in my array. Any ideas why? The file I am inputting will have a maximum of 20 words.
newArray string[20];
if (inputFile) {
while (i<20) {
inputFile >> word;
if (word.length()<2) { //gets rid of single character words
i++;
}
else{
newArray[i] = word;
cout<<newArray[i]<< " ";
}
}
inputFile.close();
}