| 5 | 1/1 | 返回列表 |
| 查看: 878 | 回復(fù): 6 | ||
| 當(dāng)前只顯示滿足指定條件的回帖,點(diǎn)擊這里查看本話題的所有回帖 | ||
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; } 為什么使用上述的文件不能正確讀取相應(yīng)的內(nèi)容呢?在用C++如何讀入大量的文件?假設(shè)文件名是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ā)表 | |
|---|---|---|---|---|
|
[考研] 一志愿北京化工大學(xué) 070300 學(xué)碩 336分 求調(diào)劑 +7 | vv迷 2026-03-22 | 7/350 |
|
|---|---|---|---|---|
|
[考研] 材料292調(diào)劑 +4 | 橘頌思美人 2026-03-23 | 4/200 |
|
|
[考研] 材料專業(yè)求調(diào)劑 +11 | hanamiko 2026-03-18 | 11/550 |
|
|
[考研] 一志愿國科過程所081700,274求調(diào)劑 +3 | 三水研0水立方 2026-03-23 | 3/150 |
|
|
[考研] 361求調(diào)劑 +3 | Glack 2026-03-22 | 3/150 |
|
|
[考研] 一志愿中南大學(xué)化學(xué)學(xué)碩0703總分337求調(diào)劑 +5 | niko- 2026-03-22 | 5/250 |
|
|
[考研] 一志愿重慶大學(xué)085700資源與環(huán)境,總分308求調(diào)劑 +7 | 墨墨漠 2026-03-23 | 8/400 |
|
|
[考研] 263求調(diào)劑 +6 | yqdszhdap- 2026-03-22 | 9/450 |
|
|
[考研] 276求調(diào)劑 +3 | YNRYG 2026-03-21 | 4/200 |
|
|
[考研] 319求調(diào)劑 +4 | 小力氣珂珂 2026-03-20 | 4/200 |
|
|
[考研] 305分求調(diào)劑(食品工程) +4 | Sxy112 2026-03-21 | 6/300 |
|
|
[考研] 303求調(diào)劑 +5 | 安憶靈 2026-03-22 | 6/300 |
|
|
[考研] 0856材料專碩353求調(diào)劑 +4 | NIFFFfff 2026-03-20 | 4/200 |
|
|
[考研] 化學(xué)調(diào)劑 +5 | yzysaa 2026-03-21 | 5/250 |
|
|
[考研] 297求調(diào)劑 +11 | 戲精丹丹丹 2026-03-17 | 12/600 |
|
|
[考研] 313求調(diào)劑 +4 | 肆叁貳壹22 2026-03-19 | 4/200 |
|
|
[考研] 266求調(diào)劑 +3 | 哇呼哼呼哼 2026-03-20 | 3/150 |
|
|
[考研] 一志愿 西北大學(xué) ,070300化學(xué)學(xué)碩,總分287,雙非一本,求調(diào)劑。 +3 | 晨昏線與星海 2026-03-18 | 3/150 |
|
|
[考研] 086500 325 求調(diào)劑 +3 | 領(lǐng)帶小熊 2026-03-19 | 3/150 |
|
|
[考研] 材料學(xué)碩318求調(diào)劑 +5 | February_Feb 2026-03-19 | 5/250 |
|