visual-c++ - google::protobuf::io::FileOutputStream 未定义?

标签 visual-c++ protocol-buffers

我正在尝试使用 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/

相关文章:

c++ - 内联和成员初始值设定项

c++ - 使用 CMake 添加文件

c++ - C++ 程序中的异常编译器错误。与语法无关。 Windows编程

使用 Protocol Buffer 错误 : too few values in struct initializer 进行构建

javascript - 协议(protocol) JSON (PSON) 与 Protocol Buffer

java - 让 Google Protobuf 2.4 和 2.5 在一个项目中同时存在

c++ - 在 g++ 中启用严格的别名警告

qt - 无法使用 JOM 构建项目

import - Protobuf 导入失败

java - j2objc/usr/local/lib//libprotobuf.a(strutil.o) ld : 55 duplicate symbols for architecture x86_64