有一个含有8个元素的整数数组,从键盘输入8个整数给数组,并将此数组的数值存放到磁盘文件shuzu.dat中。
1条回答 默认 最新
- 梦里逆天 2022-09-19 10:34关注
可参考:https://www.jb51.net/article/246257.htm
#include <iostream> #include <fstream> using namespace std; int main() { int arr[8]; for(int i=0; i<8; i++) { cin>>arr[i]; } ofstream ofs; ofs.open("shuzu.dat", ios::out); for(int i=0; i<8; i++) { ofs<<arr[i]<<endl; } ofs.close(); return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决评论 打赏 举报无用 1