//256 lines 00000000 0000000 00000001 1000000 00000010 0000010 ................ ................
我把
第1列 - &gt; std::vector<std::bitset<8> > a
第二栏 - &gt; std::vector<std::bitset<8> > b
我想比较这些向量的元素,并将任何向量中的单个元素推送到列表或队列中。我想知道如何将矢量的单个元素推入队列或列表并显示它。
我已经看到了将vector转换为队列的示例,但是如何将上面的vector元素推入其中。
例如:
00000000 == 00000000
离开
00000001 != 10000000
将00000001
推送到队列或列表中。
我编写代码直到将文件中的行读入vector并比较向量。我想知道如何将向量的单个元素推入队列或列表。
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <bitset>
using namespace std;
void pvb(std::vector<std::bitset<8> > v)
{
for(int x=0;x<v.size();++x)
{
for(int y=7;y>=0;--y)
{
std::cout << v[x][y];
}
std::cout << '\n';
}
}
int main()
{
std::vector<std::bitset<8> > a2d,b2d;
std::ifstream in("C:/Users/Lenovo/Desktop/hwb8_64.pla");
std::string Line;
if(!in) //Always test the file open.
{
cout<<"Error opening output file"<<endl;
system("pause");
return -1;
}
while(!in.eof())
{
std::getline(in,Line);
if( Line[0] != '#') //skip lines starting with '.'
{
if(Line[0] !='.')
{
if(Line == " ")
{
std::cout<<"end of the file\n";
break;
}
//vector(bitset)
istringstream is(Line);
std::string b1,b2;
while(is >> b1 >> b2)
{
std::bitset<8> x(b1);
std::bitset<8> y(b2);
a2d.push_back(x);
b2d.push_back(y);
}
}
}
}
// display the inputs and outputs
std::cout << "inputs\n";
pvb(a2d);
system("PAUSE");
std::cout << "outputs\n";
pvb(b2d);
system("PAUSE");
//compare the vectors
for(int i=0;i<a.size();i++)
{
if(a[i] == b[i]){
std::cout<< "a==b";
}
else{
// push a[i] into queue or list
// push b[i] into queue or list
}
return 0;
}
我已经看过很多关于这个主题的例子,但我无法知道如何将一个元素从vector存储到队列或列表中。