[C++] Need help with arrays with strings

Since you're using C++, there's no reason to use arrays. Use vectors instead.

My problem is that I have to write the names to two separate arrays, one for the male names, the other for the female names. I'm really stumped on how to do this and may have missed something in class but can't find it in any of my notes.

Read each line, split the line and add each name to their respective vector. Like this.

#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>

struct Names
{
    /* Two vectors: one for male names, one for female names */
    std::vector<std::string> male;
    std::vector<std::string> female;
};

auto parseFile(std::ifstream &infile)
{
    Names newNames;
    std::string line;
    std::string name;
    int i = 0;

    while(std::getline(infile, line))
    {
        std::stringstream ss(line);
        while(std::getline(ss, name, ' '))
        {
            if(i%2 == 0)
                newNames.male.push_back(name);
            else
                newNames.female.push_back(name);
            i++;
        }   
    }
    return newNames;
}

int main()
{
    std::ifstream infile("test");
    Names newNames;
    newNames = parseFile(infile);

    /* Print the male names */
    for(auto it = std::begin(newNames.male); it != std::end(newNames.male); it++)
        std::cout << *it << " ";

    return 0;
}

Have a look at std::getline() and std::basic_istream::getline().

/r/learnprogramming Thread