我正在根据目前的进展编辑我的帖子。好吧,我现在要做的是:
到目前为止我的代码:
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
string line, netlist;
int address, fout, fin;
string name, type, fsa0, fsa1;
cout << "Wich Netlist you want to use?" << endl;
cin >> netlist;
ifstream file(netlist.c_str());
if (file.is_open())
{
do{
getline(file, line);
} while ( line[0] == '*' );
file >> address >> name >> type >> fout >> fin >> fsa0;
if (fsa0 != ">sa0") { fsa1 = fsa0; fsa0 = "@"; } else { file >> fsa1; }
cout << address << " " << name << " " << type << " " << fout << " " << fin << " " << fsa0 << " " << fsa1 << endl;
} else { cout << "File not found" << endl; }
file.close();
return 0;
}
发现问题:
文本文件我试图阅读:
*c17 iscas example (to test conversion program only)
*---------------------------------------------------
*
*
* total number of lines in the netlist .............. 17
* simplistically reduced equivalent fault set size = 22
* lines from primary input gates ....... 5
* lines from primary output gates ....... 2
* lines from interior gate outputs ...... 4
* lines from ** 3 ** fanout stems ... 6
*
* avg_fanin = 2.00, max_fanin = 2
* avg_fanout = 2.00, max_fanout = 2
*
*
*
*
*
1 1gat inpt 1 0 >sa1
2 2gat inpt 1 0 >sa1
3 3gat inpt 2 0 >sa0 >sa1
8 8fan from 3gat >sa1
9 9fan from 3gat >sa1
6 6gat inpt 1 0 >sa1
7 7gat inpt 1 0 >sa1
10 10gat nand 1 2 >sa1
1 8
11 11gat nand 2 2 >sa0 >sa1
9 6
14 14fan from 11gat >sa1
15 15fan from 11gat >sa1
16 16gat nand 2 2 >sa0 >sa1
2 14
20 20fan from 16gat >sa1
21 21fan from 16gat >sa1
19 19gat nand 1 2 >sa1
15 7
22 22gat nand 0 2 >sa0 >sa1
10 20
23 23gat nand 0 2 >sa0 >sa1
21 19
而另一件事,你们可以给我一些关于如何处理这些线路的提示,只有两个整数,比如最后一个?
谢谢大家。我感谢所有的帮助。
答案 0 :(得分:0)
至少IMO,你接近这个错误的方式。我首先阅读一系列输入。然后检查该行上有多少项目。然后适当地解析行中的项目。
除非您完全专注于使用纯C ++执行此操作,否则像AWK或yacc这样的工作将使工作变得更加轻松。
如果您坚持在没有解析器生成器或类似的情况下执行此操作,您至少可以使用正则表达式来提供帮助。