我已经创建了一个二进制文件。在其中,数据以二进制形式存储,但我将以人类可读的形式显示它,例如;

 [someOtherData]6759A_block$[someOtherData]

我将数据“6759A_block $”保存在temp_S中,该数据声明为字符串。现在,我想先从temp_S拆分3个字节,然后将其存储在unsigned int中。为了实现我的愿望,我在下面的代码段中编写了代码;
 unsigned int number;
 {
 string tmp ( temp_S , 0  ,3 );
 istringstream temp_Istream ( tmp ) ;
 temp_Istream >> number;
 }

但是,当我编译我的小程序时,它给出了如下所示的错误;
error: variable ‘std::istringstream temp_S’ has initializer but incomplete type

我的问题是:
  • 此编译器错误的含义是什么?
  • 如何解决该问题,并将数据的前三个字节取为unsigned int?

  • 编辑 :
  • 平台linux
  • g++
  • 最佳答案

    当您忘记了以下内容时,GCC会给出error:

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

    关于c++ - 使用istringstream会产生错误|为什么,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8091976/

    10-13 04:58