File: testFile.cc

package info (click to toggle)
libdap 3.20.7-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 24,448 kB
  • sloc: cpp: 52,490; sh: 40,745; xml: 23,511; ansic: 20,030; yacc: 2,520; exp: 1,544; makefile: 1,057; lex: 309; perl: 52; fortran: 8
file content (38 lines) | stat: -rw-r--r-- 640 bytes parent folder | download | duplicates (2)
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
37
38
#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[0], length);
    is.close();
    buffer[length] = '\0';

    return string(&buffer[0]);
}