#include <fstream>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | int main() { ofstream out("out.out"); for (int i = 0; i < 10; i++) { out << i << " " << i * 2 << endl; } out.close(); cout << "done1" << endl; ifstream openFile("out.out"); int T; //openFile >> T; long long tmp,k; while (openFile && !openFile.eof()) { openFile >> tmp >> k; if (openFile.eof()) { break; } printf("%lld %lld\n", tmp,k); } ; openFile.close(); cout << "done2" << endl; while(1){} return 0; } | cs |
C style
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <stdio.h> int main(){ FILE *fp ; int index; int data; fp = fopen("test.txt", "w"); for(index = 0 ; index < 10 ; index++){ fprintf(fp, "%d\n", index); } fclose(fp); fp = fopen("test.txt", "r"); while(fscanf(fp, "%d", &data) != EOF){ printf("%d\n", data); } fclose(fp); return 0; } 출처: http://ra2kstar.tistory.com/53 [초보개발자 이야기.] | cs |