程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> 輸入輸出流-vs2013 fstream 無法打開文件

輸入輸出流-vs2013 fstream 無法打開文件

編輯:編程綜合問答
vs2013 fstream 無法打開文件

include

//# include

include

using namespace std;

class student
{
public:
int num;
char name[20];
float score;
};
int main()
{
student std[5] = { 1001, "Li", 85, 1002, "Fun", 97.5, 1004, "Wang", 54, 1006, "Tan", 76.5, 1010, "Ling", 96 };
fstream iofile;
iofile.open("stud.dat", ios::in|ios::out|ios::binary);
if (!iofile)
{
cerr << "Error!" << endl;
exit(1);
}
for (int i = 0; i < 5; i++)
{
iofile.write((char *)&std[i], sizeof(std[i]));
}
student stud[5];
for (int i = 0; i < 5; i = i + 2)
{
iofile.seekg(i * sizeof(std[i]), ios::beg);
iofile.read((char *)&stud[i / 2], sizeof(stud[0]));
cout << stud[i / 2].num << ' ' << stud[i / 2].name << ' ' << stud[i / 2].score << endl;
}
cout << endl;
stud[2].num = 1012;
strcpy_s(stud[2].name, 20, "Wu");
stud[2].score = 60;
iofile.seekp(2 * sizeof(stud[0]), ios::beg);
iofile.write((char *)&std[2], sizeof(std[2]));
iofile.seekg(0, ios::beg);
for (int i = 0; i < 5; i++)
{
iofile.read((char *)&stud[i], sizeof(stud[i]));
cout << stud[i].num << ' ' << stud[i].name << ' ' << stud[i].score << endl;
}
iofile.close();
return 0;
}

輸出的是Error,求解??看不出什麼錯誤!

最佳回答:


http://zhidao.baidu.com/link?url=lTdfF6UxnroZlPazozUUph_PP0tuGkpX7SY2fkx0p4Up8VrSGs8a6JpINnzYxtammHiYzJBMvXrCpZfVe4QzZSipJvmRsolSIFUrHS__nLu

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved