这个是输入的文件里面的内容
Yesterday Beatles Help! 5
Paradise Cody_Simpson <Paradise> 3
Misery Maroon_5 Hands_All_Over 4
下面是程序 只复制了一段
#define SONG_LENGTH 20
#define ARTIST_LENGTH 20
#define CD_LENGTH 20
class Song{
public:
char* song;
char* artist;
char* cd;
int rating;
Song* next;
};
int main(int argc, char** argv){
Song *head = NULL;
print_list(head);
Song *node = NULL;
int rating;
cout<< hex <<uppercase;
ifstream source(*(argv+1));
while(!source.eof()) //这个一直死循环
{
char *song = new char(SONG_LENGTH);
char *artist = new char(ARTIST_LENGTH);
char *cd = new char(CD_LENGTH);
source >> song;
source >> artist;
source >> cd;
source >> rating;
cout << song <<": song at "<<(unsigned long) song <<", artist at "<<(unsigned long) artist<<", cd at "<<(unsigned long) cd<<endl; //这个输出的是乱码
//还有(unsigned long) song什么意思 输出song字串吗
//node = new_song(song,artist,cd,rating); //这函数别管它
//head = insert_by_song(head,node); //这函数别管它
cout << endl;
}
source.close();
}
这个是运行结果 会无限循环 用的是Code blocks 写的
Yesterday Beatles Help! 5
Paradise Cody_Simpson <Paradise> 3
Misery Maroon_5 Hands_All_Over 4
下面是程序 只复制了一段
#define SONG_LENGTH 20
#define ARTIST_LENGTH 20
#define CD_LENGTH 20
class Song{
public:
char* song;
char* artist;
char* cd;
int rating;
Song* next;
};
int main(int argc, char** argv){
Song *head = NULL;
print_list(head);
Song *node = NULL;
int rating;
cout<< hex <<uppercase;
ifstream source(*(argv+1));
while(!source.eof()) //这个一直死循环
{
char *song = new char(SONG_LENGTH);
char *artist = new char(ARTIST_LENGTH);
char *cd = new char(CD_LENGTH);
source >> song;
source >> artist;
source >> cd;
source >> rating;
cout << song <<": song at "<<(unsigned long) song <<", artist at "<<(unsigned long) artist<<", cd at "<<(unsigned long) cd<<endl; //这个输出的是乱码
//还有(unsigned long) song什么意思 输出song字串吗
//node = new_song(song,artist,cd,rating); //这函数别管它
//head = insert_by_song(head,node); //这函数别管它
cout << endl;
}
source.close();
}
这个是运行结果 会无限循环 用的是Code blocks 写的