I am trying to write a program that extracts the data from the first 20 columns of a txt file, then the next 4 columns, then the data separated by white space afterwards. The txt file has many rows of information and I need to manipulate each piece of information into a formula. How can I only extract a certain portion of a string?
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
string filename, firstName, lastName, teamABV, line, fullName[30];
ifstream qbinfo;
int completions, attempts, yards, touchdowns, interceptions;
int i = 0;
int main()
{
cout << "This program will calculate the average passer rating based " << endl;
cout << "on data from a text file." << endl;
cout << "Please enter your full file's path." << endl;
cin >> filename;//Get file name for user input
qbinfo.open(filename.c_str());//Open input file
while (qbinfo.fail())//In case of error
{
cout << filename << " is an incorrect input. " << endl;
cout << "Please reenter your full file name and path." << endl;//Re-do
cin >> filename;
}
for (int i = 0; i < 20; i++)
{
getline(qbinfo,line);
fullName[i] = line;
cout << fullName[i] << endl;
}
qbinfo.close();
system("pause");
}
This is my code so far, I want to extract the first 20 characters into the string, fullName, but I am not certain how to do so. I thought it might be something to do with a for loop, but the loop seems to do # of rows instead of columns. How can I fix this?