Yurttas/PL/OOL/Cplusplus/F/06/02/01/04/io gs 04.cpp

 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   io_gs_04.cpp
14*/
15
16
17#include <vector>
18#include <string>
19
20#include <iostream>
21#include <sstream>
22
23using namespace std;
24
25int main(int argc, char* argv[]) {
26
27  string s = "4 8 2";
28
29  istringstream ins;         // construct an input string stream object.
30
31  vector<int> v;
32
33  ins.str(s);                // specify input string.
34
35  int a;
36
37  for(int i=0; i<3; ++i) {
38    ins >> a;                // input the integers from the string.
39    v.push_back(a);
40  }
41
42  for(int i=0; i<3; ++i)
43    cout << v.at(i) << endl;
44
45}