64,646
社区成员
发帖
与我相关
我的任务
分享
char tok[]="|";
char name[256]={0},artist_name[256]={0},time[10]={0},Album_name[256]={0},genre[256]={0},r[1024]={0};
char buffer[2048];
ifstream instream;
instream.open("song.dat");
while(!instream.eof())
{
instream.getline(buffer,2048);
strcpy(name,strtok(buffer,tok));
strcpy(buffer,strtok(NULL,""));
strcpy(artist_name,strtok(buffer,tok));
strcpy(buffer,strtok(NULL,""));
strcpy(time,strtok(buffer,tok));
strcpy(buffer,strtok(NULL,""));
strcpy(Album_name,strtok(buffer,tok));
strcpy(buffer,strtok(NULL,""));
strcpy(genre,strtok(buffer,tok));
//try{
strcpy(buffer,strtok(NULL,""));
strcpy(r,strtok(buffer,tok));
//}catch(){}
Song_Node* tmp=new Song_Node(name,artist_name,time,Album_name,genre,r);
if (myhead.get_Song_head()==NULL)
{
myhead.set_Songhead(tmp);
myhead.set_Songcur(tmp);
}
else{
myhead.get_Song_cur()->set_pNext(tmp);
myhead.set_Songcur(tmp);
}
}
/* strtok example */
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] ="- This, a sample string.";
char * pch;
printf ("Splitting string \"%s\" into tokens:\n",str);
pch = strtok (str," ,.-");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ,.-");
}
return 0;
}