Yurttas/PL/OOL/Cplusplus/F/02/04/04/01/get list int.cpp

From ZCubes Wiki
Jump to navigation Jump to search
 1/* 
 2   Copyright(C) 1998
 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   : January 1, 1998.
11   author : Salih Yurttas.
12
13   get_list_int.cpp
14*/
15
16
17#include <iostream>
18#include <fstream>
19
20#include <string>
21#include <vector>
22
23using namespace std;
24
25void get_list_int(vector<int>& list) {
26  string filename;
27
28  cout << "--> input filename : ";
29  cin >> filename;
30  cout << endl;
31
32  ifstream f_in(filename.c_str());
33
34  if(!f_in) {
35    cerr << "File named as " << filename << " is not opened for input." << endl;
36    exit(1);
37  }
38  else {
39    int t;
40    while(f_in>>t)
41      list.push_back(t);
42  }
43
44  f_in.close();
45}