| 7 | 1/1 | 返回列表 |
| 查看: 868 | 回復: 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; } 我這樣寫,沒有問題 |

木蟲 (職業(yè)作家)
中國特色

木蟲 (職業(yè)作家)
中國特色

| 7 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 085600材料與化工 求調(diào)劑 +14 | enenenhui 2026-03-13 | 15/750 |
|
|---|---|---|---|---|
|
[考研] 材料與化工求調(diào)劑 +7 | 為學666 2026-03-16 | 7/350 |
|
|
[考研] 317求調(diào)劑 +3 | 申子申申 2026-03-19 | 6/300 |
|
|
[考研] 328求調(diào)劑,英語六級551,有科研經(jīng)歷 +4 | 生物工程調(diào)劑 2026-03-16 | 12/600 |
|
|
[考研] 一志愿天大材料與化工(085600)總分338 +5 | 蔡大美女 2026-03-13 | 5/250 |
|
|
[考研] 085601專碩,總分342求調(diào)劑,地區(qū)不限 +5 | share_joy 2026-03-16 | 5/250 |
|
|
[考研] 0854可跨調(diào)劑,一作一項核心論文五項專利,省、國級證書40+數(shù)一英一287 +8 | 小李0854 2026-03-16 | 8/400 |
|
|
[考研] 070300化學319求調(diào)劑 +6 | 錦鯉0909 2026-03-17 | 6/300 |
|
|
[考研] 0703化學336分求調(diào)劑 +6 | zbzihdhd 2026-03-15 | 7/350 |
|
|
[考研] 277調(diào)劑 +5 | 自由煎餅果子 2026-03-16 | 6/300 |
|
|
[考研] 268求調(diào)劑 +8 | 一定有學上- 2026-03-14 | 9/450 |
|
|
[考研] 考研化學學碩調(diào)劑,一志愿985 +4 | 張vvvv 2026-03-15 | 6/300 |
|
|
[考研] 332求調(diào)劑 +6 | Zz版 2026-03-13 | 6/300 |
|
|
[考研] 275求調(diào)劑 +4 | 太陽花天天開心 2026-03-16 | 4/200 |
|
|
[考研] 考研調(diào)劑 +3 | 淇ya_~ 2026-03-17 | 5/250 |
|
|
[考研] [導師推薦]西南科技大學國防/材料導師推薦 +3 | 尖角小荷 2026-03-16 | 6/300 |
|
|
[考研] 304求調(diào)劑 +3 | 曼殊2266 2026-03-14 | 3/150 |
|
|
[考研] 0703化學調(diào)劑 290分有科研經(jīng)歷,論文在投 +7 | 膩膩gk 2026-03-14 | 7/350 |
|
|
[考研] 294求調(diào)劑 +3 | Zys010410@ 2026-03-13 | 4/200 |
|
|
[考研] 311求調(diào)劑 +3 | 冬十三 2026-03-13 | 3/150 |
|