Cannot trace array to see where it fails

I have a program that is supposed to populate an array of structs and then write the info from weeklyHits[0]. The progam compiles but nothing shows up after the "This week's num......." this statement does appear 10 times like it should. I tried putting tracers in (cout>>"j">>endl; in places to see where the failure is, but whenever I do that the program loses the #include<iostream>.


The text file it pulls from looks like this.

Sexy & I Know It | LMFAO
We Found Love | Rihanna Featuring Calvin Harris
Good Feeling |Flo Rida
Set Fire To The Rain | Adele
Party Rock Anthem | LMFAO Featuring Lauren Bennett & GoonRock
Someone Like You | Adele
It Will Rain | Bruno Mars
The One That Got Away | Katy Perry
Pumped Up Kicks | Foster The People
Young, Wild & Free | Snoop Dogg & Wiz Khalifa Featuring Bruno Mars
Set Fire To The Rain | Adele
Good Feeling | Flo Rida
Sexy & I Know It | LMFAO
We Found Love | Rihanna Featuring Calvin Harris
Someone Like You | Adele
I Won't Give Up Jason | Mraz
Domino | Jessie J
It Will Rain | Bruno Mars
Young, Wild & Free | Snoop Dogg & Wiz Khalifa Featuring Bruno Mars

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
42
43
44
45
46
47
48
49
50
51
52
53
#include<iostream>
#include<fstream>
#include<string>
#include<cstdlib>

using namespace std;

#define inFileMusic "tophits.txt"

struct music
{
    string songTitle;
    string artistName;
};

const int maxWeeks = 10;
string weeklyHits[10];

void getHits (istream&, string[]);
void numberOnes (string[]);
int main()
{
   ifstream hitIn;
   
   hitIn.open(inFileMusic);
   if (hitIn.fail())
   {
       cerr<<"ERROR: cannot open "<<inFileMusic<<"for input."<<endl;
   }
  
   getHits(hitIn, weeklyHits);
   numberOnes(weeklyHits);
   return 0;
   
}
void getHits (istream& hitIn, string weeklyHits[]) //opens external file and
{                                                  //populates array
    music songWeek[10];
        for (int i=0;i<maxWeeks;i++)
        {
         getline(hitIn,songWeek[i].songTitle, '|');
         getline(hitIn,songWeek[i].artistName);
         }
      
}       
 void numberOnes (string[])             //prints number 1 hits from array
 {      
     for (int i=0; i<maxWeeks;i++)
     {weeklyHits[i];
        
        {cout<<"This week's number one hit is"<<weeklyHits[0]<<endl;}
     }
 }
> The progam compiles but nothing shows up after the "This week's num......."
You never put anything in the array, ¿what were you expecting?

> I tried putting tracers in (cout>>"j">>endl; in places to see where the failure is,
> but whenever I do that the program loses the #include<iostream>.
¿what?
The file hitIn was supposed to load.

I put a bunch of cout commands in random places to see if I could see where the disconnect was, but every time I do that the program immediately show a problem at the #include<iostream> in the heading.
if you've got an error, you probably were doing something wrong. Not knowing what error it give you, or what you were doing that generate the error, is kind of hard to help.

> The file hitIn was supposed to load.
The only part where you touch the file is in `getHits()', where you fill a local array.
The array being local to the function, ceases to exist when the function ends.

You never touch weeklyHits, so it is obvious that it should be empty
I wasn't getting an error message, the program compiled fine. It just came up empty. Thank you, you are absolutely right about weeklyHits.
Topic archived. No new replies allowed.