c++的string类不会用,感觉像鸡肋
#define Size 100string Items[Size];void AppInit(){ FILE *ItemsToExecute=fopen("ItemsToExecute.txt","r"); if(ItemsToExecute==NULL) ItemsToExecute=fopen("ItemsToExecute.txt","w+"); else return; /*cout<<"请设置文件列表大小"<<endl; cin>>Size;*/ cout<<"请输入您想要列入切换列表的服务名称(以回车键隔开,输入‘end’结束录入):"<<endl; int i=0; do { cin>>Items[i]; //全局变量 if(i==0) fwrite(Items[i].c_str(),sizeof(Items[i])+1,1,ItemsToExecute); else { fwrite("\n",sizeof("\n"),1,ItemsToExecute); fwrite(Items[i].c_str(),sizeof(Items[i])+1,1,ItemsToExecute); } //测试代码 printf("items %d, size:%d",i,sizeof(Items[i])); // 大小始终为32字节 printf("int size:%d",sizeof(int)); // 大小为4字节 printf("char size:%d",sizeof(char)); i++; }while(i<Size&&strcmp(Items[i].c_str(),"end")!=0); fclose(ItemsToExecute);}fwrite(Items[i].c_str(),sizeof(Items[i])+1,1,ItemsToExecute);