C++如何将向量的一个元素BIT集推到队列或列表中
我已经看过很多关于这个主题的例子,但我不知道如何将vector中的单个元素存储到队列或列表中。push[…]进入列表或队列-您的代码不包含任何这些内容。我不理解嵌套std::vector的必要性。对于a3d和b3d,std::vector不足以满足std::vector的要求。我想知道如何仅将向量a中的0000000 1推送到队列,而不是整个向量。 //256 lines 00000000 0000000 00000001 1000000 00000010 0000010 ................ ................C++如何将向量的一个元素BIT集推到队列或列表中,c++,list,vector,queue,C++,List,Vector,Queue,我已经看过很多关于这个主题的例子,但我不知道如何将vector中的单个元素存储到队列或列表中。push[…]进入列表或队列-您的代码不包含任何这些内容。我不理解嵌套std::vector的必要性。对于a3d和b3d,std::vector不足以满足std::vector的要求。我想知道如何仅将向量a中的0000000 1推送到队列,而不是整个向量。 //256 lines 00000000 0000000 00000001 1000000 00000010 0000010 ...........
#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;
}