首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

报文数据处理

2013-04-20 
报文数据处理求救?#include iostream#include fstream#include stringusing namespace stdvoid mai

报文数据处理求救?

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void main()
{
//void ReadDataFromFileLBLIntoString()
    ifstream fin("E://data.txt");  
   // ifstream fin("data.txt");  
    string s,t,p;  
    while( fin >> s )   //每次读取一行
    {         
t+=s;     //将所读取的数据的所有行组合成新的数组t
    }
cout<<t<<endl;
cout<<dec<<endl;
for(int i=0;i<t.length;i++)
{
switch(t[i])
{
case '-':  break ;
default:switch(t[i+1])
{
case '-':p+=t[i];break;
default:p+=t[i]*16+t[i+1];
}
}
}
cout<<p<<endl;

}

报文数据:4-0-41-DD-F1-60-16-92-7-97-AF-0-0-1-A-3-E9-13-20-1-73-18-1-6F-30-1-E1-21-40-3-20-51-19-0-F-0-BD-0-5-0-0-4E-20-0-0-0-32-0-0-3-EA-13-20-1-73-18-1-48-20-1-BB-21-40-3-20- 其中-为字节区分符号,我写上面代码的作用就是想一来将数据读取进字符串数组中,二来在数组中将-去掉,把两个-之间的数据弄进一个字符串数组中,那么我就可以处理数据了。。。

可是上面的代码报错啊,不知道怎么修改了,其高手啊
[解决办法]
字符在计算机里面是ANSI编码的,所以要查表再减去一个数才行

热点排行