[問題] linked list
假設我要讀一個檔 然後存在struct裡 然後顯示在螢幕上
1.txt的內容是 3
100 26
5 1
6 5
1
9 8
我該怎麼寫
目前只想到這樣
主程式哪要怎寫?
cout跟 把檔案的內容存到struct裡要怎寫?
謝謝
#include <iostream>
#include <fstream>
using namespace std;
struct Polynomials //定義結構
{ int num;
int exponents;
int coefficients;
struct poly* next;
};
int main()
{
ifstream fin("1.txt"); //開檔
cout << "內容"<<endl;
if(!fin){ cout << "讀檔失敗" << endl; } // 檢查讀檔成功與否
while (fin.good())
cout << ( ) fin.get();
^^^^^
fin.close(); // 關閉檔案
system("pause");
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.117.163.201
※ 編輯: zx33571163 來自: 59.117.163.201 (07/26 21:40)
※ 編輯: zx33571163 來自: 59.117.163.201 (07/26 21:41)
→
07/26 21:44, , 1F
07/26 21:44, 1F
→
07/26 21:45, , 2F
07/26 21:45, 2F
→
07/26 21:46, , 3F
07/26 21:46, 3F
→
07/26 21:48, , 4F
07/26 21:48, 4F
→
07/26 21:49, , 5F
07/26 21:49, 5F
2->num 100 5->exponent 26 1->coefficients
我就是資料怎麼存到struct裡 不太會= =
※ 編輯: zx33571163 來自: 59.117.163.201 (07/26 21:54)
推
07/26 22:16, , 6F
07/26 22:16, 6F
→
07/26 22:16, , 7F
07/26 22:16, 7F
推
07/26 22:22, , 8F
07/26 22:22, 8F
→
07/26 22:24, , 9F
07/26 22:24, 9F
→
07/26 22:26, , 10F
07/26 22:26, 10F
→
07/26 22:27, , 11F
07/26 22:27, 11F
→
07/26 22:28, , 12F
07/26 22:28, 12F
→
07/26 22:47, , 13F
07/26 22:47, 13F
→
07/26 22:52, , 14F
07/26 22:52, 14F
→
07/26 22:52, , 15F
07/26 22:52, 15F
如果我1.txt的內容是 2
100 26
5 3
6 5
1
9 8
我要怎麼判斷2跟1出現時他是項數?
謝謝
※ 編輯: zx33571163 來自: 59.117.163.201 (07/26 23:15)
推
07/26 23:45, , 16F
07/26 23:45, 16F
→
07/26 23:46, , 17F
07/26 23:46, 17F
→
07/26 23:54, , 18F
07/26 23:54, 18F
→
07/26 23:54, , 19F
07/26 23:54, 19F
推
07/27 06:17, , 20F
07/27 06:17, 20F
→
07/27 06:19, , 21F
07/27 06:19, 21F
→
07/27 06:19, , 22F
07/27 06:19, 22F
→
07/27 17:09, , 23F
07/27 17:09, 23F
討論串 (同標題文章)