c++ - 错误 : unqualified ID

标签 c++

我正在尝试将二进制数据写入文件流 out,我已将其打开为 std::ios::binary。我正在尝试使用 ostream::write 写入它。

int S = 0;
int space = htobe32(-120);

for (int g = 0; g < Z; ++g) 
        {
            for (int h = 0; h < Y; ++h) 
            {
                for (int i = 0; i < X; ++i)
                {
                    if (data_array[g][h][i] != 0)
                    {
                        S=htobe32(data_array[g][h][i]);
                        out.write(&S, std::sizeof(S));
                    }
                    else
                    {                
                        out.write(&space, std::sizeof(space));
                    }
                }                  
            }
         }

目前我在尝试写出的两个地方都收到了error: expected unqualified-id before ‘sizeof’

最佳答案

sizeof() 是一个语言运算符,不是标准库的一部分,所以你不能在它前面加上std:

 sizeof(anything)

关于c++ - 错误 : unqualified ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28342577/

相关文章:

c++ - Mat OpenCv 分配错误

c++ - 我应该使用 Perl 的哪些动态编程特性?

c++ - 如何输出 vector ?

c++ - 使用 Boost.Python 将 Python 转换为 C++ 函数

c++ - 如何使用 boost::thread_group 使用多客户端服务器?

C++ 返回多个项目

C++ fork() 和 execv() 问题

c# - C++ NamedPipeClientStream 发送数据

c++ - Cin.clear() 问题

c++ - 在 qDebug() 中避免换行