无法从字符串流接收信息
Can't receive info from string stream
所以我试图使用std::stringstream
将信息序列化为字符串,但编译器不喜欢我。
enum PacketType : unsigned int {
PacketType_unknown = 0,
PacketType_ping,
PacketType_server_welcome,
PacketType_client_greetings,
};
std::stringstream ss;
unsigned int v;
PacketType p;
ss << (unsigned int)somevalue;
// error here
ss >> p;
错误是:
no match for 'operator>>' (operand types are 'std::stringstream' {aka
'std::__cxx11::basic_stringstream<char>'} and 'PacketType')GCC
编辑:忘记添加这么多东西,因为我认为这并不重要
我终于想通了,我的代码不起作用的原因是......
PacketType
!=unsigned int
. PacketType是它自己的类型。即使它基于unsigned int
.
所以我所要做的就是
unsigned int s;
ss >> s;
somevalue = static_cast<PacketType>(s);
虽然还是很奇怪... 不应该PacketType
继承unsigned int
.
相关文章:
- 正在查找文档以获得PS4平台的C++中的设备信息
- 无法从字符串流接收信息
- 在C++中,我想通过使用来自变量(例如字符串)的typename信息,从模板中定义一个类对象
- 如何创建一个C++程序来读取字符串数组中的信息,然后将其排序到类中?
- 有没有办法从字符串中提取某些信息?C++
- 拆分字符串信息的最大相等子字符串数
- 编译器在遇到提取或插入运算符时处理信息(字符串、操纵器等)的顺序是什么?
- 解析来自字符串流的信息
- 如何使用空格将信息放入字符串中?(来自数组)
- 当我的着色器文件的所有信息都被正确读取到字符串中并且语法正确时,OpenGL为什么会出现语法错误
- 无法在C++中找出指针!需要有关基本字符串和指针的信息
- 如何将字符串行作为cl_uint数组和文件详细信息传递给GPGPU
- 使用具有冗余信息的键字符串的映射
- 什么是最快的方式来获得日期,时间和解析成字符串以及一些其他信息
- 从printf格式字符串中提取类型信息
- 存储在异常对象中的信息:在异常中提供字符串
- fscanf,逗号文本文件信息字符串和数字
- 从文件中以字符串格式读取信息
- 如何在结构数组中搜索字符串(名称)并返回该字符串的信息
- 矢量<string>以及映射<字符串,整数> 释放时可能失败? 想知道内存使用情况详细信息