herrDeng網內搜尋

自訂搜尋

Ads

2016年12月2日 星期五

Ex10 struct與文字檔讀寫

struct與文字檔讀寫

7 則留言:

B10133186 提到...

#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>
using namespace std;

struct student
{
int id;
string name;
int java;
int math;
int cpp;
bool sex;
};

void print(student X, ostream& ff)
{
ff << X.id << "," ;
ff << X.name << ",";
ff << X.java << ",";
ff << X.math << ",";
ff << X.cpp << ",";
ff << X.sex << ",";
ff << "\n";

}
void read(student&X, fstream& ff)
{
ff >> X.id;
ff >> X.name;
ff >> X.java;
ff >> X.math;
ff >> X.cpp;
ff >> X.sex;
}
int main()
{
student Y[10];
fstream ff, fout;
ff.open("test.txt", ios::in);
fout.open("ost.csv", ios::out);
for (int i = 0; i < 10; i++)
{
read(Y[i], ff);
print(Y[i], cout);
print(Y[i],fout);
}
fout.close();
ff.close();
system("Pause");
return 0;
}

b10233127 提到...

#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>
using namespace std;

struct student
{
int id;
string name;
int java;
int math;
int cpp;
bool sex;
};

void print(student X, ostream& ff)
{
ff << X.id << "," ;
ff << X.name << ",";
ff << X.java << ",";
ff << X.math << ",";
ff << X.cpp << ",";
ff << X.sex << ",";
ff << "\n";

}
void read(student&X, fstream& ff)
{
ff >> X.id;
ff >> X.name;
ff >> X.java;
ff >> X.math;
ff >> X.cpp;
ff >> X.sex;
}
int main()
{
student Y[10];
fstream ff, fout;
ff.open("test.txt", ios::in);
fout.open("ost.csv", ios::out);
for (int i = 0; i < 10; i++)
{
read(Y[i], ff);
print(Y[i], cout);
print(Y[i],fout);
}
fout.close();
ff.close();
system("Pause");
return 0;
}

b10233072黃宥婕 提到...

#include
#include
#include
#include
using namespace std;

struct student
{
int id;
string name;
int java;
int math;
int cpp;
bool sex;
};

void print(student X, ostream& ff)
{
ff << X.id << "," ;
ff << X.name << ",";
ff << X.java << ",";
ff << X.math << ",";
ff << X.cpp << ",";
ff << X.sex << ",";
ff << "\n";

}
void read(student&X, fstream& ff)
{
ff >> X.id;
ff >> X.name;
ff >> X.java;
ff >> X.math;
ff >> X.cpp;
ff >> X.sex;
}
int main()
{
student Y[10];
fstream ff, fout;
ff.open("test.txt", ios::in);
fout.open("ost.csv", ios::out);
for (int i = 0; i < 10; i++)
{
read(Y[i], ff);
print(Y[i], cout);
print(Y[i],fout);
}
fout.close();
ff.close();
system("Pause");
return 0;
}

b10233074 提到...

#include
#include
#include
#include
using namespace std;

struct student
{
int id;
string name;
int java;
int math;
int cpp;
bool sex;
};

void print(student X, ostream& ff)
{
ff << X.id << "," ;
ff << X.name << ",";
ff << X.java << ",";
ff << X.math << ",";
ff << X.cpp << ",";
ff << X.sex << ",";
ff << "\n";

}
void read(student&X, fstream& ff)
{
ff >> X.id;
ff >> X.name;
ff >> X.java;
ff >> X.math;
ff >> X.cpp;
ff >> X.sex;
}
int main()
{
student Y[10];
fstream ff, fout;
ff.open("test.txt", ios::in);
fout.open("ost.csv", ios::out);
for (int i = 0; i < 10; i++)
{
read(Y[i], ff);
print(Y[i], cout);
print(Y[i],fout);
}
fout.close();
ff.close();
system("Pause");
return 0;
}

b10233074 提到...

#include
#include
#include
#include
using namespace std;

struct student
{
int id;
string name;
int java;
int math;
int cpp;
bool sex;
};

void print(student X, ostream& ff)
{
ff << X.id << "," ;
ff << X.name << ",";
ff << X.java << ",";
ff << X.math << ",";
ff << X.cpp << ",";
ff << X.sex << ",";
ff << "\n";

}
void read(student&X, fstream& ff)
{
ff >> X.id;
ff >> X.name;
ff >> X.java;
ff >> X.math;
ff >> X.cpp;
ff >> X.sex;
}
int main()
{
student Y[10];
fstream ff, fout;
ff.open("test.txt", ios::in);
fout.open("ost.csv", ios::out);
for (int i = 0; i < 10; i++)
{
read(Y[i], ff);
print(Y[i], cout);
print(Y[i],fout);
}
fout.close();
ff.close();
system("Pause");
return 0;
}

B10233077 提到...

#include
#include
#include
#include
using namespace std;

struct student
{
int id;
string name;
int java;
int math;
int cpp;
bool sex;
};

void print(student X, ostream& ff)
{
ff << X.id << "," ;
ff << X.name << ",";
ff << X.java << ",";
ff << X.math << ",";
ff << X.cpp << ",";
ff << X.sex << ",";
ff << "\n";

}
void read(student&X, fstream& ff)
{
ff >> X.id;
ff >> X.name;
ff >> X.java;
ff >> X.math;
ff >> X.cpp;
ff >> X.sex;
}
int main()
{
student Y[10];
fstream ff, fout;
ff.open("test.txt", ios::in);
fout.open("ost.csv", ios::out);
for (int i = 0; i < 10; i++)
{
read(Y[i], ff);
print(Y[i], cout);
print(Y[i],fout);
}
fout.close();
ff.close();
system("Pause");
return 0;
}

B10233077 提到...

#include
#include
#include
#include
using namespace std;

struct student
{
int id;
string name;
int java;
int math;
int cpp;
bool sex;
};

void print(student X, ostream& ff)
{
ff << X.id << "," ;
ff << X.name << ",";
ff << X.java << ",";
ff << X.math << ",";
ff << X.cpp << ",";
ff << X.sex << ",";
ff << "\n";

}
void read(student&X, fstream& ff)
{
ff >> X.id;
ff >> X.name;
ff >> X.java;
ff >> X.math;
ff >> X.cpp;
ff >> X.sex;
}
int main()
{
student Y[10];
fstream ff, fout;
ff.open("test.txt", ios::in);
fout.open("ost.csv", ios::out);
for (int i = 0; i < 10; i++)
{
read(Y[i], ff);
print(Y[i], cout);
print(Y[i],fout);
}
fout.close();
ff.close();
system("Pause");
return 0;
}

Related Posts Plugin for WordPress, Blogger...

熱門文章