使用c++进行数据解析
data parsing using c++
.i 8.o 8.ilb a b c d e f g h.ob a b c d e f g h00000000000000000000000 1 00000011。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。e
我试过这样的代码。没有编译错误
#include <string>
#include <iostream>
#include <sstream>
#include <vector>
#include <bitset>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include "Line12.hpp"
#include "Line34.hpp"
#include "Line261.hpp"
using namespace std;
void printLine12(Line12 line1)
{
cout << "first:" << line1.getFirst() << endl;
cout << "in:" << line1.getIn() << endl;
}
int main(int argc, const char * argv[])
{
std::vector<Line12> lines12;
std::vector<Line34> lines34;
std::vector<std::vector<std::bitset<8> > > a;
std::vector<Line261> lines261;
std::ifstream in("C:/Users/Lenovo/Desktop/hwb8_64.pla");
std::string Line;
for(int i=1; i<=261;i++)
{
std::getline(in,Line);
if(i==1 || i==2)
{
Line12 s(Line);
lines12.push_back(s);
}
else if(i==3 || i==4)
{
Line34 s1(Line);
lines34.push_back(s1);
}
else if(i==261)
{
Line261 s2(Line);
lines261.push_back(s2);
}
else
{
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<=261;i++)
{
if(i==1 || i==2)
{
Line12 s1 = lines12.at(i);
printLine12(s1);
}
else if(i==3 || i==4)
{
Line34 s2 = lines34.at(i);
printLine34(s2);
}
else if(i==261)
{
Line261 s3 = lines261.at(i);
printLine261(s3);
}
else
{
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;
}
但是当我运行代码时。它是这样显示的。我该怎么做才能纠正这一点。
terminate called after throwing an instance of 'std::invalid_argument'
what<>: bitset::_M_copy from ptr
我应该做些什么来纠正这个错误并得到输出。
bitset
构造函数接受一个1和0的string
。如果您传递的不是1和0的东西,它将抛出invalid_argument
异常。你确实通过了一些不仅仅是1和0的东西,现在你来了。
在这里发布之前,请自己进行一些基本的调试,以验证您的程序是否正常工作。
相关文章:
- 防止主数据类型C++的隐式转换
- 用于访问容器<T>数据成员的正确 API
- 嵌套在类中时无法设置成员数据
- 使用流处理接收到的数据
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 在cuda线程之间共享大量常量数据
- C++将文本文件中的数据读取到结构数组中
- 如何在C++中序列化结构数据
- 在C++中打印指向不同基元数据类型的指针的内存地址
- 通过套接字[TCP]传输数据 如何在C / C ++中打包多个整数并使用send() recv()传输数据
- 在c代码之间共享数据的最佳方式
- 链表,反向函数,数据结构
- 数据成员SFINAE的C++17测试:gcc vs clang
- C++浮点数据类型和字符串数据类型无法子到模板函数中
- 如何对点云数据进行排序
- 从矢量<无符号字符>转换为字符* 包括垃圾数据
- 尝试通过OCI例程从Oracle获取blob数据,但出现错误:ORA-01008:并非所有变量都绑定
- Cuda C++:设备上的Malloc类,并用来自主机的数据填充它
- 在运行时处理类型擦除的数据-如何不重新发明轮子