[homework] Need some Help array and data file

so i have a couple of errors but my main question is using one data file to read into two different arrays. In my code i have a data file that is a list of baby names it is in the data file like this
1. noah sophia
2. liam emma
And so on it has 1000 entries and i need help getting the first name in a boy name array (mname) and the second in a girl name array (fnames) so in total the program is to let someone search a name in both array and output the locations that they are. Yes i know that the output isnt there yet but thats a quick cout if anyone can help would be very helpful!

#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

void askName (string& name);
int search (string arr[], int 1001, string name);

int main () {
ifstream in_stream;
in_stream.open("babynames.txt");
string mnames[1001], fnames[1001];
int i, mloc, floc;
i=0;
while (in_stream >> i){
cin >> mname[i] >> fname[i];
}
}
askName (name);
mloc= search (mname[], 1001, name);
floc= search (fname[], 1001, name);


void askName (string& name){
cout << "Enter a name" << endl;
cin >> name;
}

int search (string arr[], 1001, string name){
int i;
i=0;
if (arr[i]!= name){
while (i << 1001)
i++;
}
return i;
}
Quick demo how to read the file into the arrays, maybe you can adopt it.
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
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

const int NUM_NAMES = 1000;

int main()
{
  string mnames[NUM_NAMES], fnames[NUM_NAMES];
  ifstream input("Names.txt");
  if (!input)
  {
    perror(0);
    exit(-1);
  }
  int i = 0;
  while (input >> mnames[i] >> fnames[i] && i++ < NUM_NAMES)
    ;
  for (int i = 0; i < NUM_NAMES; i++)
    cout << mnames[i] << "\t\t" << fnames[i] << "\n";

  system("pause");
  return 0;
}
Topic archived. No new replies allowed.