I need to read the 5 words from a input file mine is called words.txt I am unable to get to work correctly everytime I put inFile >> words[5]; instead of cin >> words[5]; I get a debug error and prog shuts down and nothing is showing up for errors or warnings
here is my code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ifstream inFile;
ofstream outFile;
int numbers[5];
int counter;
string words[5];
inFile.open("numbers.txt");
outFile.open("output.txt");
cout << "Processing information from numbers file...." << endl;
for(counter=0; counter < 5; counter++)
{
inFile >> numbers[counter];
}
cout << "\nInformation stored successfully! "<<endl;
for(counter = 4; counter >= 0; counter--)
{
outFile << numbers[counter] << endl;
}
cout << "\nProcessing five words already input from file...." << endl;
inFile.close();
inFile.open("words.txt");
for(counter = 0; counter < 5; counter++)
{
inFile >> words[counter];
}
words[counter] = "end_of_array";
counter = 0;
do
{
cout << words[counter].substr(0,1) << words[counter].substr(2,1) << endl;
counter++;
}
while(words[counter]!= "end_of_array");
inFile.close();
outFile.close();
return 0;
}