本文介绍了使用向量读取输入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个代码来读文件,但它不工作。
输入文件:
I have written a code to read file below but its not working.Input file:
2 1 16
16 0 0
1 1 1234
16 0 0
1 1 2345
代码是:
std::ifstream input_file;
evl_wire wire;
int num_pins,width,cycles,no;
std::vector<int>IP;
while(input_file)
{
input_file >> num_pins;//num_pins=2
if (pins_.size() != num_pins) return false;
for (size_t i = 0; i < pins_.size(); ++i)
{
input_file >> width;//width=1 for 1=0 ,=16 for i=2
if (wire.width != width) return false;
pins_[i]->set_as_output();
}
for (size_t i = 1; i < file_name.size(); i=i+1)
input_file>>cycles;
input_file>>no;
pins_=IP;
}
其中 std :: vector< pin * pins _;
在门类中, void set_as_output();
在引脚类
中2表示引脚数,引脚和第二引脚的宽度。
这里从文件16的第二行开始没有循环引脚必须保持为0 0,对于下一个1周期,引脚必须分配1和1234作为输入。
where std::vector<pin *> pins_;
is in gate class and void set_as_output();
is in pin class 2 represent no of pins,1 width of first pin and 16 width of second pin. here from second line in file 16 is no of cycles pins must remain at 0 0,for next 1 cycle pins must be assigned 1 and 1234 as inputs.
推荐答案
我不完全理解你的代码,但我没有看到你打开输入文件在任何地方。我认为应该是:
I don't fully understand your code, but I don't see you are opening the input file anywhere. I think it should be:
std::ifstream input_file;
evl_wire wire;
int num_pins,width,cycles,no;
std::vector<int>IP;
input_file.open("name of the file");
if(input_file.is_open())
{
while(input_file >> num_pins) //num_pins=2
{
if (pins_.size() != num_pins) return false;
for (size_t i = 0; i < pins_.size(); ++i)
{
input_file >> width;//width=1 for 1=0 ,=16 for i=2
if (wire.width != width) return false;
pins_[i]->set_as_output();
}
for (size_t i = 1; i < file_name.size(); i=i+1)
input_file>>cycles;
input_file>>no;
pins_=IP;
}
input_file.close();
}
这篇关于使用向量读取输入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!