[問題] C++ 讀檔 動態陣列 指標
遇到的問題: (題意請描述清楚)
讀取以下文字檔並分類做輸出存成文字檔
.model sample01
.inputs a b c d e
.outputs h j
.names b c d f←想存成b:1 c:0 d:1 f:1 or f=bc'd
101 1
.names b c d g←想存成g=bc+d
11- 1
--1 1
.names a f h←想存成h=a+f'
1- 1
-0 1
.names e f g i
110 1
001 1
.names i j
0 1
.end
希望得到的正確結果:
f=bc'd
g=bc+d
h=a+f'
i=efg'+e'f'g
j=i'
程式跑出來的錯誤結果:
開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux)
G++
補充說明:
因為讀到的node不一定是字元a b c有時候可能是一個字串ex:0_11 0_22
想知道要如何存起來,想過陣列和linklist利用指標
先創一個struct做分類再用陣列存起來
但是要怎麼讀到空白'/n'去做個判別
以下是我練習讀取資料並加以判別之後才要做存取
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ifstream infile;
infile.open ("要讀的檔", ifstream::in);
string op;
int i=0;
while (! infile.eof())
{
infile>>op;
if(op==".names")
cout<<"+";
if(op=='\n')←讀不到 是因為只讀的到字串嗎?
cout<<"enter";
cout<<op<<endl;
i++;
}
cout<<i<<endl;
infile.close();
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.25.53.81
※ 編輯: dannys258 來自: 114.25.53.81 (09/19 16:40)
→
09/19 16:42, , 1F
09/19 16:42, 1F
→
09/19 16:50, , 2F
09/19 16:50, 2F
→
09/19 16:54, , 3F
09/19 16:54, 3F
推
09/20 22:03, , 4F
09/20 22:03, 4F
→
09/20 22:13, , 5F
09/20 22:13, 5F
→
09/20 22:23, , 6F
09/20 22:23, 6F
→
09/21 09:52, , 7F
09/21 09:52, 7F
→
09/21 10:01, , 8F
09/21 10:01, 8F
→
09/21 10:03, , 9F
09/21 10:03, 9F
※ 編輯: dannys258 來自: 140.138.152.174 (09/21 12:27)
→
09/21 12:28, , 10F
09/21 12:28, 10F
→
09/21 17:27, , 11F
09/21 17:27, 11F
→
09/22 03:11, , 12F
09/22 03:11, 12F
→
09/22 10:44, , 13F
09/22 10:44, 13F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章