使用istringstream给出错误|为什么 [英] Using istringstream gives error | Why

查看:202
本文介绍了使用istringstream给出错误|为什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我创建的二进制文件。在其中,数据以二进制形式存储,但是我将以人类可读的形式显示它:

  [someOtherData] 6759A_block $ [ someOtherData] 



我在temp_S中保存数据6759A_block $,声明为字符串。现在,我想要拆分第一个3字节远离temp_S,然后将其存储在unsigned int。要完成我的愿望,我写下面的代码段;

  unsigned int number; 
{
string tmp(temp_S,0,3);
istringstream temp_Istream(tmp);
temp_Istream>>数;然而,当我编译我的小程序时,它给出一个错误如下所示;然而,当我编译我的小程序,它给出一个错误,如下所示:。
}



<

 错误:variable'std :: istringstream temp_S'具有初始化器但不完整类型



我的问题是:




  • 编译器错误?

  • 如何解决这个问题,并将前三个字节的数据转换为unsigned int?



编辑:




  • 平台linux

  • g ++


解决方案

GCC指出错误< a>当你忘记这一点:

  #include< sstream> // this is where istringstream is defined 


I have one binary file which I have created. In it, data is stored in binary form but I will show it in human readable form like ;

 [someOtherData]6759A_block$[someOtherData]

I hold that data "6759A_block$" in temp_S, which is declared as string. Now, I want split first 3 byte away from temp_S, and then store it in unsigned int. To accomplish my wish, I have write below code segment;

 unsigned int number;
 { 
 string tmp ( temp_S , 0  ,3 ); 
 istringstream temp_Istream ( tmp ) ;
 temp_Istream >> number;
 }

However, when I compile my small program, it gives an error shown below ;

error: variable ‘std::istringstream temp_S’ has initializer but incomplete type

My questions are :

  • What is the meaning of this compiler error ?
  • how can I fix that problem, and take first three byte of data to unsigned int ?

EDIT :

  • platform linux
  • g++

解决方案

GCC gives that error when you forget this:

#include <sstream> //this is where istringstream is defined

这篇关于使用istringstream给出错误|为什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆