| 5 | 1/1 | 返回列表 |
| 查看: 879 | 回復: 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ā)表 | |
|---|---|---|---|---|
|
[考研] 086003食品工程求調(diào)劑 +4 | 淼淼111 2026-03-24 | 4/200 |
|
|---|---|---|---|---|
|
[基金申請] 請教下大家 2026年國家基金申請是雙盲審嗎? +3 | lishucheng1 2026-03-22 | 5/250 |
|
|
[考研] 361求調(diào)劑 +3 | Glack 2026-03-22 | 3/150 |
|
|
[考研] 384求調(diào)劑 +3 | 子系博 2026-03-22 | 6/300 |
|
|
[考研] 269求調(diào)劑 +4 | 我想讀研11 2026-03-23 | 4/200 |
|
|
[考研] 一志愿211 初試270分 求調(diào)劑 +4 | 谷雨上岸 2026-03-23 | 5/250 |
|
|
[考研] 化學308分求調(diào)劑 +3 | 你好明天你好 2026-03-23 | 3/150 |
|
|
[考研] 350求調(diào)劑 +6 | weudhdk 2026-03-19 | 6/300 |
|
|
[考研] 315分,誠求調(diào)劑,材料與化工085600 +3 | 13756423260 2026-03-22 | 3/150 |
|
|
[考研] 303求調(diào)劑 +5 | 安憶靈 2026-03-22 | 6/300 |
|
|
[考研] 考研調(diào)劑 +4 | 來好運來來來 2026-03-21 | 4/200 |
|
|
[考研] 354求調(diào)劑 +7 | Tyoumou 2026-03-18 | 10/500 |
|
|
[考研] 一志愿華中科技大學071000,求調(diào)劑 +4 | 沿岸有貝殼6 2026-03-21 | 4/200 |
|
|
[考研] 302求調(diào)劑 +12 | 呼呼呼。。。。 2026-03-17 | 12/600 |
|
|
[基金申請]
學校已經(jīng)提交到NSFC,還能修改嗎?
40+4
|
babangida 2026-03-19 | 9/450 |
|
|
[考研] 材料學學碩080502 337求調(diào)劑-一志愿華中科技大學 +4 | 順順順mr 2026-03-18 | 5/250 |
|
|
[考研] 材料 336 求調(diào)劑 +3 | An@. 2026-03-18 | 4/200 |
|
|
[考研] 一志愿武理材料305分求調(diào)劑 +6 | 想上岸的鯉魚 2026-03-18 | 7/350 |
|
|
[考研] 一志愿武漢理工材料工程專碩調(diào)劑 +9 | Doleres 2026-03-19 | 9/450 |
|
|
[考研] 290求調(diào)劑 +7 | ^O^乜 2026-03-19 | 7/350 |
|