基本上我的问题是如何使用对象数组将数据导入重载构造函数,我首先从纺织品中读取数据,然后想要使用重载构造函数设置这些值但是我如何做一个对象数组我的代码在下面,我知道通常没有数组它将是歌曲组成员(参数的数量);我的代码在下面
#include <iostream>// Program By Richard Okpala 1/30/2018
#include <string>// libaries used for program
#include <fstream>
using namespace std;
#include "song.h"
int main() {
ifstream myfile;
ofstream outfile;
string first_name, last_name, Artist_name, song_name, song_duration, given_genre;//variables used to get data into class
song GroupMember[35];
/*song GroupMember1, GroupMember2, GroupMember3, GroupMember4, GroupMember5, GroupMember6, GroupMember7, GroupMember8, GroupMember9, gorupMember10
, GroupMember11, GroupMember12, GroupMember13, GroupMember14, GroupMember15, GroupMember16, GroupMember17, GroupMember18, GroupMember19, GroupMember20, GroupMember21, GroupMember22
, GroupMember23, GroupMember24, GroupMember25, GroupMember26, GroupMember27, GroupMember28, GroupMember29, GroupMember30, GroupMember31, GroupMember32, GroupMember33, GroupMember34, GroupMember25;*/
myfile.open("myfile.txt");
outfile.open("class.txt");
if (myfile.is_open()) {
cout << "Could not open the file" << endl;
}
int counter = 0;
while (!myfile.eof()) {
getline(myfile, first_name, '\t');
getline(myfile, last_name, '\t');
getline(myfile, Artist_name, '\t');
getline(myfile, song_name, '\t');
getline(myfile, song_duration, '\t');
getline(myfile, given_genre, '\t');
}
myfile.close();
}
#include <iostream>
#include <string>
using namespace std;
#include "song.h"
song::song(string given_first, string given_last, string given_artist, string given_song, string given_duration, string given_genre)
{
the_first = given_first;
the_last = given_last;
the_artist = given_artist;
the_song = given_song;
the_durartion = given_duration;
the_genre = given_genre;
return;
}