我正在尝试使用 Protocol Buffer 将多条消息序列化到一个文件中 - 按照所示的实现 here - 但我遇到了无法访问 FileOutputStream
的问题<zero_copy_stream_impl.h>
中定义的类.
根据API documentation , FileOutputStream
类在命名空间 google::protobuf::io
下- 但我能在这个命名空间下看到的唯一定义是 CodedOutputStream
, CodedInputStream
, ZeroCopyOutputStream
, 和 ZeroCopyInputStream
.
有没有人知道如何解决这个问题?仅供引用,我正在使用带有 protobuf-2.4.0a 构建的 Microsoft Visual Studio 2010。这是我的代码片段和生成的错误消息(智能感知和编译器错误):
int outfd = _open(fileName.c_str(), _O_CREAT | _O_BINARY | _O_APPEND | _O_WRONLY);
google::protobuf::io::ZeroCopyOutputStream *output = new google::protobuf::io::FileOutputStream(outfd);
警告 C4996:“_open”:此函数或变量可能不安全。考虑改用 _sopen_s。要禁用弃用,请使用 _CRT_SECURE_NO_WARNINGS。
IntelliSense:需要一个类型说明符
错误 C2061:语法错误:标识符“FileOutputStream”
错误 C2039:“FileOutputStream”:不是“google::protobuf::io”的成员
最佳答案
看来我的代码明确要求这样做:
#include <google/protobuf/io/zero_copy_stream_impl.h>
我认为默认情况下会包含它,但显然情况并非如此。感谢 Kenton Varda 指出这一点。
关于visual-c++ - google::protobuf::io::FileOutputStream 未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24890944/