#include <iostream>
#include <fstream>
using namespace std;

int main()
{
  double fnum[4] = {9.5, -3.4, 1.0, 2.1};
  int i;

  ofstream out("numbers", ios::out | ios::binary);
  if(!out) {
    cout << "Cannot open file.";
    return 1;
   }

  out.write((char *) &fnum, sizeof fnum);

  out.close();

  for(i=0; i<4; i++) // clear array
    fnum[i] = 0.0;

  ifstream in("numbers", ios::in | ios::binary);
  in.read((char *) &fnum, sizeof fnum);

  // see how many bytes have been read
  cout << in.gcount() << " bytes read\n";

  for(i=0; i<4; i++) // show values read from file
  cout << fnum[i] << " ";

  in.close();

  return 0;
}

32 bytes read
9.5 -3.4 1 2.1 "

Save and read double array in a binary file的更多相关文章

  1. Binary file to C array(bin2c)

    /******************************************************************************** * Binary file to C ...

  2. 【转】B树、B-树、B+树、B*树、红黑树、 二叉排序树、trie树Double Array 字典查找树简介

    B  树 即二叉搜索树: 1.所有非叶子结点至多拥有两个儿子(Left和Right): 2.所有结点存储一个关键字: 3.非叶子结点的左指针指向小于其关键字的子树,右指针指向大于其关键字的子树: 如: ...

  3. ubuntu安装jdk遇到的问题:cannot execute binary file

    安装完jdk,配置好环境变量出现如下状况: cannot execute binary file 问题原因: jdk的位数与ubuntu的系统位数不一致 jdk 64位 ubuntu 32位 然后通过 ...

  4. linux出现bash: ./java: cannot execute binary file 问题的解决办法

    问题现象描述: 到orcal官网上下载了两个jdk: (1)jdk-7u9-linux-i586.tar.gz ------------>32位 (2)jdk-7u9-linux-x64.tar ...

  5. grep:Binary file (standard input) matches

    grep "key" xxx.log时输出 Binary file xxx.log matches 百度了一下:grep觉得这是二进制文件.解决方式:grep -a. grep - ...

  6. java: cannot execute binary file

    转自:http://jxwpx.blog.51cto.com/15242/222572 java: cannot execute binary file 如果遇到这个错,一般是操作系统位数出问题了. ...

  7. javac: cannot execute binary file

    # java/jdk1.6.0_12/bin/javac-bash: java/jdk1.6.0_12/bin/javac: cannot execute binary file   后来检验,检查了 ...

  8. -bash: /tyrone/jdk/jdk1.8.0_91/bin/java: cannot execute binary file

    问题描述:今天在linux环境下安装了一下JDK,安装成功后,打算输入java -version去测试一下,结果却出错了. 错误信息:-bash: /tyrone/jdk/jdk1.8.0_91/bi ...

  9. linux环境下运行程序格式错误的问题,bash: ./helloworld: cannot execute binary file: Exec format error

    在编译完quecOpen的example helloworld之后,我运行此程序,结果报错,详情如下: ricks@ubuntu:~/share/project/ql-ol-sdk/ql-ol-ext ...

随机推荐

  1. 详解js闭包

    https://segmentfault.com/a/1190000000652891 闭包(closure)是Javascript语言的一个难点,也是它的特色,很多高级应用都要依靠闭包实现. 闭包的 ...

  2. ASP.NET页面支持的指令

    页面的处理指令 页面指令的处理用于配置执行该页面的运行时环境.在ASP.NET中,指令可以位于页面的任何位置,但良好且常见的习惯是将其置于文件的开始部分.除此,页面指令的名称是不区分大小写的,且指令的 ...

  3. [javaSE] IO流(装饰设计模式)

    装饰设计模式:当想要对已有的对象进行功能增强时,可以自定义类将已有的对象传入,并提供加强功能,自定义的该类称为装饰类 典型的: Reader--FileReader --BufferedReader ...

  4. 从MySQL到ORM(二):MySQL基础

    一.基本概念 1.数据库: 数据库(DataBase)就是一个存储数据的仓库,为了方便数据的存储和管理,它将数据按照特定的规律存储在磁盘上.通过数据库管理系统,可以有效的组织和管理存储在数据库中的数据 ...

  5. 设计模式入门,适配器模式,c++代码实现

    // test07.cpp : Defines the entry point for the console application.// #include "stdafx.h" ...

  6. 2.springioc实例化bean的三个方法

    1.构造器 也就是在上一篇讲的那个例子,调用默认的无参构造函数 2.静态工厂方法 1)创建需要执行的方法的类 public class HelloWorld { public HelloWorld() ...

  7. JS计算十万块钱 分31期 利息万分之五 每个月的还款数

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. vue2.0路由写法

    // 0. 如果使用模块化机制编程,導入Vue和VueRouter,要调用 Vue.use(VueRouter) // 1. 定义(路由)组件. // 可以从其他文件 import 进来 var Fo ...

  9. 微服务架构之spring cloud zipkin

    Spring Cloud Zipkin是微服务的链路跟踪组件,帮助详细了解一次request&response的总计时,及每个微服务的消耗时间.微服务名称.异常信息等等过程信息. (一) 版本 ...

  10. GDAL读取影像并插值

    影像读取 并缩放 读取大影像某一部分,并缩放到指定大小,我们有时会用如下代码: #include "gdal.h" #include "gdal_priv.h" ...