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;}
}
}
|