【问题标题】:Using istringstream gives error | Why使用 istringstream 会出错 |为什么
【发布时间】:2011-12-26 21:04:45
【问题描述】:

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

 [someOtherData]6759A_block$[someOtherData]

我将数据“6759A_block$”保存在 temp_S 中,它被声明为字符串。现在,我想将前 3 个字节从 temp_S 中分离出来,然后将其存储在 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++

【问题讨论】:

标签: c++ string split


【解决方案1】:

当您忘记这一点时,GCC 会给出 error

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

【讨论】:

  • @sehe:是的。我刚刚测试了它,所以相应地改变了答案。
猜你喜欢
  • 1970-01-01
  • 2018-04-16
  • 2014-11-21
  • 2019-11-05
  • 1970-01-01
  • 2021-05-22
  • 1970-01-01
  • 1970-01-01
  • 2021-03-04
相关资源
最近更新 更多