c++ - 使用 Google 的 protobuf 时出错

标签 c++ protocol-buffers

#include <google/protobuf/io/coded_stream.h>
namespace google::protobuf::io

....
int fd = open("myfile", O_WRONLY);
ZeroCopyOutputStream* raw_output = new FileOutputStream(fd);
CodedOutputStream* coded_output = new CodedOutputStream(raw_output);

以上是跟随教程here ,但是当我编译时出现以下错误:

error C2061: syntax error : identifier 'io'

这里有什么问题吗?

更新

当我将上面的内容更改为 using namespace google::protobuf::io; 时,我收到一个新错误,指出符号 FileOutputStream 未定义,这是怎么回事?

最佳答案

为了回应关于为什么未声明 FileOutputStream 的更新问题...

我觉得你需要

#include <google/protobuf/io/zero_copy_stream_impl.h>

根据文档:

http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.io.zero_copy_stream_impl.html

This file contains common implementations of the interfaces defined in zero_copy_stream.h which are only included in the full (non-lite) protobuf library.

These implementations include Unix file descriptors and C++ iostreams.

关于c++ - 使用 Google 的 protobuf 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3576044/

相关文章:

c++ - 具有默认参数和特化的模板

java - 使用 RProtoBuf( Protocol Buffer )从 R 调用 Java 函数

android - 我在 Android 的 Proguard 配置中缺少什么?

protocol-buffers - Google Protocol Buffer 错误 : "Encountered string containing invalid UTF-8 data while serializing protocol buffer"

sockets - 通过 Akka IO 和套接字的 Protocol Buffer 消息

c++ - 通过存储在字符串中的名称创建类的对象?

c++ - 所有文件的 Makefile

C# pinvoke 具有 union 和数组的结构

c++ - Microsoft 的 GCC 选项 init_priority 是什么?

android - 使用 C++ 和 Android NDK 解析包含字符串的 protobuf 消息时崩溃