| 7 | 1/1 | 返回列表 |
| 查看: 1749 | 回復(fù): 6 | ||
hegongda123銅蟲 (小有名氣)
|
[求助]
關(guān)于C++中讀取txt文件中字符串
|
|
txt文件內(nèi)容如下: ALLSEL,ALL !選擇所有實體 ANTYPE,4 TRNOPT,FULL SFL,2,CONV,14.6, ,25, SFL,5,CONV,48.148, ,25, !定義熱流密度表 *DIM,reliuZHONG,TABLE,300 /SOLU !位移限制 !DL,4,,UY,, !DL,13,,UY,, !對上式樣 請問怎么把這行“*DIM,reliuZHONG,TABLE,300”讀取出來,因為我要隨時改變300,我想讀出來修改為200或者100或者125 ....之后再放回原處,請指教..... 能推薦函數(shù)代碼更好啦 |
|
#include<iostream> #include<fstream> #include<string> #include<vector> using namespace std; int main() { vector<string> svec; cout<<"請輸入要讀取的文件名:"<<endl; string fileName; cin>>fileName; ifstream inFile(fileName.c_str()); if(!inFile) { cout<<"文件讀取錯誤!"<<endl; return -1; } string s; while(inFile) { inFile>>s; // cout<<s.size()<<endl; svec.push_back(s); } inFile.close(); cout<<"數(shù)據(jù)讀取結(jié)果:"<<endl<<endl; int i=0; string ss; for(vector<string>::const_iterator iter=svec.begin();iter!=svec.end()-1;iter++) { if (iter==svec.begin()) i=1; if (i==10) { ss=*iter; cout<<*iter<<endl; break; } i++; } cout<<ss<<endl; cout<<ss.size()<<endl; return 0; } 注意:文件名即txt文件的名稱 |

銅蟲 (小有名氣)
銅蟲 (小有名氣)
銅蟲 (小有名氣)
| 7 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 一志愿中南化學(xué)(0703)總分337求調(diào)劑 +9 | niko- 2026-03-19 | 10/500 |
|
|---|---|---|---|---|
|
[考研] 275求調(diào)劑 +6 | shansx 2026-03-22 | 8/400 |
|
|
[考研] 求調(diào)劑院校信息 +6 | CX 330 2026-03-21 | 6/300 |
|
|
[考研]
|
酥酥魚.. 2026-03-21 | 3/150 |
|
|
[考研] 材料工程專碩 348分求調(diào)劑 +3 | 冬辭. 2026-03-17 | 5/250 |
|
|
[考研] 313求調(diào)劑 +4 | 肆叁貳壹22 2026-03-19 | 4/200 |
|
|
[考研] 307求調(diào)劑 +3 | 余意卿 2026-03-18 | 3/150 |
|
|
[考研] 332求調(diào)劑 +3 | 鳳凰院丁真 2026-03-20 | 3/150 |
|
|
[考研] 一志愿山大07化學(xué) 332分 四六級已過 本科山東雙非 求調(diào)劑! +3 | 不想理你 2026-03-16 | 3/150 |
|
|
[考研] 070300化學(xué)319求調(diào)劑 +7 | 錦鯉0909 2026-03-17 | 7/350 |
|
|
[考研] 初始318分求調(diào)劑(有工作經(jīng)驗) +3 | 1911236844 2026-03-17 | 3/150 |
|
|
[考研] 一志愿 西北大學(xué) ,070300化學(xué)學(xué)碩,總分287,雙非一本,求調(diào)劑。 +3 | 晨昏線與星海 2026-03-18 | 3/150 |
|
|
[考研] 一志愿南京理工大學(xué)085701資源與環(huán)境302分求調(diào)劑 +4 | 葵梓衛(wèi)隊 2026-03-18 | 6/300 |
|
|
[考研] 一志愿武漢理工材料工程專碩調(diào)劑 +9 | Doleres 2026-03-19 | 9/450 |
|
|
[考研] 085600材料與化工 +8 | 安全上岸! 2026-03-16 | 8/400 |
|
|
[考研] 0817 化學(xué)工程 299分求調(diào)劑 有科研經(jīng)歷 有二區(qū)文章 +22 | rare12345 2026-03-18 | 22/1100 |
|
|
[考研] 08工學(xué)調(diào)劑 +5 | 用戶573181 2026-03-20 | 5/250 |
|
|
[考研] 招收調(diào)劑碩士 +4 | lidianxing 2026-03-19 | 12/600 |
|
|
[考研] 328求調(diào)劑,英語六級551,有科研經(jīng)歷 +4 | 生物工程調(diào)劑 2026-03-16 | 12/600 |
|
|
[考研] 材料專碩306英一數(shù)二 +10 | z1z2z3879 2026-03-16 | 13/650 |
|