am doing a project with I/O and structs. My text file is below. I need to make my program store each string in a different part of the array of structs I have created. I am having a problem making it separate them in the array when it senses a blank line.

Steps for the program: 1. Read each line with data and store it in the struct array until it reaches a blank line. 2. Output each string in a different group or on a different line.

Text file:

ecl:gry pid:860033327 hcl:#fffffd
byr:1937 iyr:2017 cid:147 hgt:183cm

iyr:2013 ecl:amb cid:350 pid:028048884
hcl:#cfa07d byr:1929

hcl:#ae17e1 iyr:2013 cid:150
eyr:2024
ecl:brn pid:760753108 byr:1931
hgt:179cm

hcl:#cfa07d eyr:2025 pid:166559648
iyr:2011 ecl:brn hgt:59in cid:230
My code:


#include <iostream>
#include <fstream>
#include <sstream>
#include <string>

const int SIZE = 4;

struct Passport{

    std::string singlePass;

};

int main()
{
    Passports records[SIZE];
    std::string fileName = "some_file.txt";
    std::ifstream inFile(fileName);
    std::string line, data;
    if (inFile.is_open()){
        while (!inFile.eof()) {
            getline(inFile, line);
            std::istringstream ss(line);
            for (int i = 0; i < SIZE; i++) {
                while (ss >> records[i].singlePass) {
                    std::cout << records[i].singlePass;
                }

            }
        }
    }
    else {
        std::cout << "Error opening file! " << std::endl;
    }   
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.