user198729
user198729

Reputation: 63626

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?

Upvotes: 1

Views: 2900

Answers (3)

ahochhaus
ahochhaus

Reputation: 382

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.

Upvotes: 2

Puppy
Puppy

Reputation: 146900

#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.

Upvotes: 1

Steve Townsend
Steve Townsend

Reputation: 54128

Don't you mean

using namespace google::protobuf::io;

Upvotes: 1

Related Questions