| 5 | 1/1 | 返回列表 |
| 查看: 888 | 回復: 6 | |||
| 當前只顯示滿足指定條件的回帖,點擊這里查看本話題的所有回帖 | |||
youngfi木蟲 (小有名氣)
|
[求助]
C++讀入大批量文件
|
||
|
#include<iostream> #include <fstream> #include <string.h> #include <stdio.h> using namespace std; int main() { int i,natom; char filename[10]; for (i=0;i<3;i++) { sprintf(filename,"t%d.txt",i); cout<<filename<<endl; ifstream infile("filename",ios: ut);infile.seekg(49,ios::beg); infile>>natom; cout<<natom<<endl; } cout<<"Successfully!"<<endl; return 0; } 為什么使用上述的文件不能正確讀取相應的內(nèi)容呢?在用C++如何讀入大量的文件?假設文件名是t1.txt, t2.txt,t3.txt.... |

木蟲 (職業(yè)作家)
中國特色
|
#include<iostream> #include<string> #include<stdio.h> using namespace std; int main() { int i, natom; char filename[10]; //寫文件 for (i=0; i<3; i++){ sprintf(filename,"t%d.txt",i); cout << filename <<endl; FILE *fp=fopen(filename,"w" ;fprintf(fp,"0\n" ;fclose(fp); } //讀文件 for (i=0; i<3; i++){ sprintf(filename,"t%d.txt",i); cout << filename <<endl; FILE *fp=fopen(filename,"r" ;fscanf(fp,"%d\n",&natom); printf("%d\n",natom); fclose(fp); } return 0; } 我這樣寫,沒有問題 |

木蟲 (正式寫手)

木蟲 (小有名氣)

木蟲 (小有名氣)

| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研]
材料調劑
5+5
|
想要一壺桃花水 2026-03-25 | 11/550 |
|
|---|---|---|---|---|
|
[考研] 求調劑 +7 | 11ggg 2026-03-30 | 7/350 |
|
|
[考研] 機械學碩總分317求調劑。。! +5 | Acaciad 2026-03-25 | 5/250 |
|
|
[考研] 328求調劑 +3 | 鵬鵬碰嘭嘭 2026-03-24 | 3/150 |
|
|
[考研] 085600材料與化工329分求調劑 +5 | 這是有太陽哇 2026-03-25 | 5/250 |
|
|
[考研] 吉大生物學326分求調劑 +3 | sunnyupup 2026-03-31 | 3/150 |
|
|
[考研] 一志愿鄭大材料工程290求調劑 +12 | Youth_ 2026-03-30 | 12/600 |
|
|
[考研] 求調劑,一志愿 南京航空航天大學 ,080500材料科學與工程學碩,總分289分 +9 | @taotao 2026-03-29 | 9/450 |
|
|
[考研] 303求調劑 +7 | DLkz1314. 2026-03-30 | 7/350 |
|
|
[考研] 生物學學碩,一志愿湖南大學,初試成績338 +7 | YYYYYNNNNN 2026-03-26 | 9/450 |
|
|
[考研] 抱歉 +3 | 田洪有 2026-03-30 | 3/150 |
|
|
[考研] 0703化學求調劑 +6 | 丹青奶蓋 2026-03-26 | 8/400 |
|
|
[考研] 334分 一志愿武理 材料求調劑 +16 | 李李不服輸 2026-03-26 | 16/800 |
|
|
[考研] 332求調劑 +6 | @MZB382400 2026-03-28 | 6/300 |
|
|
[考研] 303求調劑 +7 | DLkz1314. 2026-03-30 | 7/350 |
|
|
[考研] 337求調劑 +6 | 《樹》 2026-03-29 | 6/300 |
|
|
[考研] 085404求調劑,總分309,本科經(jīng)歷較為豐富 +6 | 來財aa 2026-03-25 | 6/300 |
|
|
[考研] 085600,材料與化工321分求調劑 +10 | 大饞小子 2026-03-28 | 10/500 |
|
|
[考研] 081200-314 +3 | LILIQQ 2026-03-27 | 4/200 |
|
|
[考研] 085601 材料工程 313分 求調劑 +5 | Ong3 2026-03-27 | 5/250 |
|