结束了。这是我保留的最后一道题目了
- #include<iostream>
- #include<fstream>
- #include<string>
- #include<iomanip>
- #include<strstream>
- using namespace std;
- struct student
- {
- int num;
- char name[20];
- float score;
- };
- int main()
- {
- student stud[3]={1001,"Li",78,1002,"Wang",89.5,1004,"Fun",90};
- char c[50];
- ostrstream strout(c,50);
- for(int i=0;i<3;i++)
- strout<<stud[i].num<<" "<<stud[i].name<<" "<<stud[i].score<<" ";
- strout<<ends;
- cout<<"array c:"<<c<<endl;
- student read[3];
- istrstream re(c,50);
- for(int i=0;i<3;i++)
- re>>read[i].num>>read[i].name>>read[i].score;
- for(int i=0;i<3;i++)
- cout<<"号码:"<<read[i].num<<"姓名:"<<read[i].name<<"成绩:"<<read[i].score<<endl;
- }