# 實做 - 檔案讀取函數 ``` #include <iostream> #include <fstream> #include <cstdio> #include <windows.h> using namespace std; int data(); int main() { int a = data(); cout << a << endl; return 0; } int data() { fstream fin; fin.open("func.txt"); if(!fin) return false; int n, i = -1; fin >> n; cout << n << endl; int *a = (int*) malloc(n * sizeof(int)); double b; while(!fin.eof()) { i++; if(i + 1 > n) return false; fin >> b; if( b >= 2147483647 || b <= -21474836477) return false; a[i] = b; cout << a[i] << endl; } if(i + 1 < n) return 0; return true; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up