关于C++文件流的问题
求解答C++中如何实现同一文件的输出和输入?代码如下:classXManagerList{public: intn; XManager*head,*p...
求解答C++中如何实现同一文件的输出和输入?代码如下:
class XManagerList{
public :
int n ;
XManager * head , * p ;
XManagerList()
{
n = 0 ;
p = head = NULL ;
}
void inputFile() ;
void saveFile() ;
} X ;
void XManagerList::inputFile()
{
XManager * t ;
char na[50] ;
ifstream cinx ("X.txt") ;
while(cinx >> na )
{
t = new XManager() ;
t -> next ;
strcpy(t -> name , na ) ;
cinx >> (t -> post ) >> (t -> sex) >> (t -> num) >> (t -> age) >> (t -> salary) ;
addMember(X , t ) ;
}
}
void XManagerList::saveFile()
{
XManager * t ;
ofstream cout ("X.txt") ;
for(t = X.head ; t != NULL ; t = t ->next )
cout<< (t -> name)<<' ' << (t -> post ) <<' '<< (t -> sex) <<' '<< (t -> num)
<<' '<< (t -> age) <<' '<< (t -> salary)<<endl ;
}
展开
class XManagerList{
public :
int n ;
XManager * head , * p ;
XManagerList()
{
n = 0 ;
p = head = NULL ;
}
void inputFile() ;
void saveFile() ;
} X ;
void XManagerList::inputFile()
{
XManager * t ;
char na[50] ;
ifstream cinx ("X.txt") ;
while(cinx >> na )
{
t = new XManager() ;
t -> next ;
strcpy(t -> name , na ) ;
cinx >> (t -> post ) >> (t -> sex) >> (t -> num) >> (t -> age) >> (t -> salary) ;
addMember(X , t ) ;
}
}
void XManagerList::saveFile()
{
XManager * t ;
ofstream cout ("X.txt") ;
for(t = X.head ; t != NULL ; t = t ->next )
cout<< (t -> name)<<' ' << (t -> post ) <<' '<< (t -> sex) <<' '<< (t -> num)
<<' '<< (t -> age) <<' '<< (t -> salary)<<endl ;
}
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询