I’m having trouble with making an array of structures in C++. For some reason,
this won’t compile. The errors point towards the Fem structure, but blame it on missing ‘;’ and missing headers for functions. The idea is to get an array of structs with an array and a string inside of each one. Any help on this would be greatly appreciated.
/* Global headers and namespace */
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cstdlib>
#include <cctype>
using namespace std;
/* ================================================================ */
/* Global named constants */
const int NUM_ANSWERS = 10;
const int NUM_STRUCTS = 15;
/* ================================================================ */
/* Global type definitions */
// Two struct types, Male and Female
struct Male
{
int maleAnswers [NUM_ANSWERS];
string name;
};
struct Fem
{
int femAnswers [NUM_ANSWERS];
string name;
};
// Arrays of structs
typedef Fem FemList [NUM_STRUCTS];
typedef Male MaleList [NUM_STRUCTS];
/* ================================================================ */
/* global function prototypes */
void OutputHeader ();
void ReadFile (FemList, MaleList);
/* ================================================================ */
int main ()
{
FemList fList; // Array of Fem structs
MaleList mList; // Array of Male structs
void OutputHeader ();
void ReadFile (fList, mList);
}
void OutputHeader ()
{
cout << "==================================================================" << endl;
cout << "Welcome to the Cheap & Ineffective Dating Service of Tallahassee!" << endl << endl;
cout << " eDisHarmony.com" << endl;
cout << "==================================================================" << endl << endl;
cout << "<><><> Initial Client Data as Input <><><>" << endl << endl;
cout << setw(11) << "Sex" << setw(31) << "Answers" << "Name" << endl;
cout << setw(11) << "---" << setw(24) << "-------------------" << "--------------------" << endl;
}
void ReadFile (fList, mList)
{
}
should be
and
should be
Below code should be working. Note, I enhanced it a bit, not sure this is what you want?
1. provide full namespace for identifier from std
2. pass parameters by reference to ReadFile. Do you want to read file into FemList and MaleList, is that your intention?