[問題] 改txt檔中的資料

看板C_and_CPP作者 (htymrednuht)時間14年前 (2010/04/06 00:55), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
想要更改txt文檔中的資料但輸出結果不對 現在在test.txt中存了 123 123456 7890123 4567890 c 123 sjdfhj knvdsnk lvnklsd c 123 dsf c 這與原本的資料結構類似 123是名稱 後面亂七八糟的是這個名稱下的資料 分成三段是因為檔案資料太長 原始文件就是這種格式 下面的C表示是C群 現在發現分群錯誤 要輸入名稱將C改為S 程式碼如下: #include <string> #include <iostream> #include <fstream> using namespace std; int main() { string q, name, data, signal, empty; int p; fstream seperation("test.txt", ios::in | ios::out | ios::binary); while (q != "q") { cout << "Imput datanames you want to transfer and press q to quit."; cin >> q; while (!seperation.eof()) { seperation >> name; getline(seperation, data); p = seperation.tellg(); seperation >> signal; if (name == q) { cout << name << data << endl << signal << endl; seperation.seekg(p); seperation.write("s", 1); name = data = signal = empty; } } seperation.clear(); seperation.seekg(0); } seperation.close(); } 結果 使用dev-c++只會出來一筆 123 123456 7890123 4567890 c 也只會改這一筆 txt打開會變成 123 123456 7890123 4567890 s 123 sjdfhj knvdsnk lvnklsd c 123 dsf c 想請問要怎麼修改呢? 謝謝各位 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.32.97.87

04/06 11:44, , 1F
還是有什麼資料或是書可以看? 謝謝各位
04/06 11:44, 1F

04/06 13:24, , 2F
查查 boost 的 regex_match 函式 這蠻好用的
04/06 13:24, 2F
文章代碼(AID): #1BkXNnn4 (C_and_CPP)