使用c++从文件中提取三维矢量
3d vectors from file using c++
文本文件的数据如下所示。
.i 8
.o 8
00000000 00000000
00010001 00010010
00000100 01000000
请注意,在第一列中,0和1是独立的。我想将这些数据解析为3d矢量-3行2列,每列8个元素为整数类型并显示矢量。
我试过这样的代码
#include <string>
#include <iostream>
#include <sstream>
#include <vector>
#include <bitset>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include "Line12.hpp"
using namespace std;
void printLine12(Line12 line1)
{
cout << "first:" << line1.getFirst() << endl;
cout << "in:" << line1.getIn() << endl;
}
int main()
{
std::vector<Line12> lines12;
std::vector<std::vector<std::bitset<8> > > a;
std::ifstream in("C:/Users/Lenovo/Desktop/hwb8_64.pla");
std::string Line;
for(int i=1; i<=258;i++)
{
std::getline(in,Line);
if(i==1 || i==2)
{
Line12 s(Line);
lines12.push_back(s);
}
else if(i >= 3 && i<=258)
{
a.push_back(std::vector< std::bitset<8> >());
std::istringstream iss(Line);
std::string bits;
while (iss >> bits)
{
a.back().push_back(std::bitset<8>(bits));
}
}
}
system ("PAUSE");
for(int i=1; i<=258;i++)
{
if(i==1 || i==2)
{
Line12 s1 = lines12.at(i);
printLine12(s1);
}
else if(i>=3 && i<=258)
{
for (int x = 0; x < a.size(); ++x)
{
for (int y = 0; y < a[i].size(); ++y)
{
for (int z = 7; z >= 0; --z)
{
std::cout << a[x][y][z];
}
std::cout << " ";
}
std::cout << std::endl;
}
}
}
system ("PAUSE");
return 0;
}
我收到一个错误std::invalid_argument --> bitset::_M_copy_from _ptr
如何删除此错误?
实时演示链接。
#include <string>
#include <iostream>
#include <sstream>
#include <vector>
#include <bitset>
#include <fstream>
int main()
{
std::vector< std::vector< std::bitset<8> > > v3d;
std::ifstream in(path_to_file);
std::string line;
while (std::getline(in, line))
{
v3d.push_back(std::vector< std::bitset<8> >());
std::istringstream iss(line);
std::string bits;
while (iss >> bits)
{
v3d.back().push_back(std::bitset<8>(bits));
}
}
for (int i = 0; i < v3d.size(); ++i)
{
for (int j = 0; j < v3d[i].size(); ++j)
{
for (int k = 7; k >= 0; --k)
{
std::cout << v3d[i][j][k];
}
std::cout << " ";
}
std::cout << std::endl;
}
}
相关文章:
- 如何将三维尺寸不固定的三维阵列展平为一维阵列
- 如何使用qt缩放三维网格
- 三维数组中的C/C++DWORD到BYTE和BYTE到DWORD的转换
- 使用vtkImageReslice重新切片三维原始图像
- 特征:创建一个具有函数的三维阵列
- 扩充矩阵的行缩减-三维样条曲线计算
- 使用pcl transformcloud将三维点平移并旋转到原点
- 用C++从三维矢量中删除元素
- 如何访问CGAL三维三角测量中的面
- 如何在Openscenegraph中从二维鼠标点击的屏幕坐标点计算三维点(世界坐标)
- std::将三维数组复制到三维向量中
- 显示结构的三维数组
- 如何将X 2维数组连接到一个三维阵列中
- 使用unique_ptr来管理三维数组
- 如何访问三维矩阵元素
- 无法访问三维数组中的特定位置
- 如何将 HDC 位图快速复制到三维阵列?
- 从三维模型中提取碎石
- 使用c++从文件中提取三维矢量
- 如何将二维图像指定给三维OpenCV Mat的平面,然后沿不同的轴提取二维Mat