Question: Here is my code: #include #include #include #include #include using namespace std; int main ( ) { / / TODO add code to solve Part

Here is my code:
#include
#include
#include
#include
#include
using namespace std;
int main(){
// TODO add code to solve Part B Question 2
ifstream inputFile("input.txt");
if (!inputFile.is_open()){
cerr << "There is an error opening this file" << endl;
return 1;
}
vector letters;
string line;
while (getline(inputFile, line)){
stringstream ss(line);
string token;
while (getline(ss, token, ',')){
letters.push_back(token);
}
}
for (int i = letters.size()-1; i >=0; i --){
if (i %2==0){
cout << letters[i]<< endl;
}
}
cout << endl;
inputFile.close();
return 0;
}
Here are my directions: Provide the code (in main.cpp) to solve the following problem:
You are given a file called input.txt that contains several lines of letters/tokens delimited by a semicolon. Your task is to read and parse every line, placing each letter/token in a vector called letters.
Once finished reading the file, print each letter that exists in an even position/index within the vector, moving from the end of the list to the beginning of the list.
Example - If the file contained (this is in the text_input.txt file in Replit as well):
5;4;3;2;1
The output you print should be:
135
Here is my current output that is incorrect:
l; ;x
a;x
h; ;k
e;e;x;s;4; ;1;s;4;i;3;h;2
a;8;H;r; ;x;!;a;r;y;e;g;t
i;e;k;d;g;n;x;o;7
.;x;r;v;e;q;m;p
Can you help me avoid the skipped line before the last line of output and determine why this program is not sorting correctly.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!