简体   繁体   English

使用Google的protobuf时出错

[英]Error when using Google's protobuf

#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);

The above is following the tutorial here , but when I compile get the following errors: 以上是下面的教程在这里 ,但是当我编译得到以下错误:

error C2061: syntax error : identifier 'io'

What can be wrong here? 这里有什么问题?

UPDATE UPDATE

When I changed the above to using namespace google::protobuf::io; 当我将上述更改为using namespace google::protobuf::io; I get a new error saying the symbol FileOutputStream is not defined, how come? 我收到一个新错误,说未定义符号FileOutputStream ,怎么来?

In response to the updated question about why FileOutputStream is not declared... 为了回应有关为何未声明FileOutputStream的更新问题...

I think you need 我觉得你需要

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

Per the docs: 根据文档:

http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.io.zero_copy_stream_impl.html 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. 该文件包含zero_copy_stream.h中定义的接口的通用实现,这些接口仅包含在完整的(非精简版)protobuf库中。

These implementations include Unix file descriptors and C++ iostreams. 这些实现包括Unix文件描述符和C ++ iostream。

你不是说

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

This is ill-formed. 这是不正确的。 You need to be using namespace google::protobuf::io; 您需要using namespace google::protobuf::io; , I'm guessing from the rest of the posted code. ,我从发布的其余代码中猜测。

How come is that the code segment for the top is for that header only, and the tutorial depends on the whole library. 顶部的代码段仅适用于该标头,而本教程取决于整个库。 You're just copy and pasting code without even understanding it. 您只是复制和粘贴代码,甚至不了解它。 I'm not going to sit here and debug every error you could possibly come up against. 我不会坐在这里调试可能遇到的每个错误。 You will have to actually read the library pages and know C++ first. 您将必须实际阅读库页面并首先了解C ++。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM