Yurttas/PL/OOL/Cplusplus/F/07/03/00/01/05/get map.cpp

From ZCubes Wiki
Jump to navigation Jump to search
 1/*
 2   Copyright(C) 2005
 3   All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
 4
 5   Permission to use, copy, modify, and distribute this
 6   software and its documentation for EDUCATIONAL purposes
 7   and without fee is hereby granted provided that this
 8   copyright notice appears in all copies.
 9
10   date   : September 1, 2005.
11   author : Salih Yurttas.
12
13   get_map.cpp
14*/
15
16
17#include "common.h"
18#include "io.h"
19
20string get_string(string);
21
22map<int, string, less<int> > get_map() {
23
24  map<int, string, less<int> > data;
25
26  string filename = get_string("input [ string ] filename : ");
27
28  ifstream f_in(filename.c_str());
29
30  if(!f_in) {
31    cerr << "File named as " << filename << " is not opened for input." << endl;
32    exit(1);
33  }
34  else {
35    int i;
36    string s;
37
38    while(f_in >> i) {
39      f_in >> s;
40
41      data[i] = s;
42    }
43  }
44
45  f_in.close();
46
47  return data;
48}