Something wrong in my code...

My output is not what's I expect.
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
#include <iostream>
#include <string>

using namespace std;


struct MusicTrack{
	string artist;
	string genre;
	string trackLength;
	string format;
	string title;
	
};

void getTracks(MusicTrack[], int SIZE);

int main(){
	const int SIZE=3;

	MusicTrack info[SIZE]={{"Beyonce", "rock", "65:22", "digital", "lemonade"},
	{"Sylvan Esso", "epop", "6:01", "digital", "Kick Jump Twist"},
	{"Paul Simon", "folk", "2:01", "vinyl", "7 O'Clock News/Silent Night"}};
	
	getTracks(info, SIZE);
}

void getTracks(MusicTrack temp[], int SIZE){
	
	temp=new MusicTrack[SIZE];
	
	for (int i=0; i<SIZE; i++){
		cout<<temp[i].artist<<", "<<temp[i].genre<<", "
		<<temp[i].trackLength<<", "<<temp[i].format<<", "
		<<temp[i].title<<endl<<endl;
		
	}
}

Here is the output
, , , ,

, , , ,

, , , ,

Don't know what I did wrong, it didn't print out all the data.
temp=new MusicTrack[SIZE]; delete this line and it should work.
What is the purpose of line 30?
 
	temp=new MusicTrack[SIZE];


Try removing that line and see what happens.
Remove temp = new MusicTrack[SIZE];
Thank you guys so much!
No, new is used to allocate memory.

pointerVariable = new type;

It creates a spot in memory for a variable of type and returns a pointer to that spot in memory.
Topic archived. No new replies allowed.