File: testFile.cc

package info (click to toggle)
libdap 3.21.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,256 kB
  • sloc: cpp: 46,310; sh: 44,047; xml: 23,535; ansic: 19,973; yacc: 2,505; exp: 1,544; makefile: 581; lex: 309; fortran: 8
file content (36 lines) | stat: -rw-r--r-- 645 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "config.h"

#include <fstream>
#include <string>
#include <vector>

#include "testFile.h"

using namespace std;

string read_test_baseline(const string &fn) {
    int length;

    ifstream is;
    is.open(fn.c_str(), ios::binary);

    if (!is)
        return "Could not read baseline file: " + fn;

    // get length of file:
    is.seekg(0, ios::end);
    length = is.tellg();

    // back to start
    is.seekg(0, ios::beg);

    // allocate memory:
    vector<char> buffer(length + 1);

    // read data as a block:
    is.read(buffer.data(), length);
    is.close();
    buffer[length] = '\0';

    return string(buffer.data());
}