Extracting specific information

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?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
using namespace 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?
I want to extract the first 20 characters into the string

Read about std::string::substr
Topic archived. No new replies allowed.