简体   繁体   中英

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

When I changed the above to using namespace google::protobuf::io; I get a new error saying the symbol FileOutputStream is not defined, how come?

In response to the updated question about why FileOutputStream is not declared...

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

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.

你不是说

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; , 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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