Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. // filestream.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. using namespace std;
  6.  
  7.  
  8. int _tmain(int argc, _TCHAR* argv[])
  9. {
  10.     vector<int> v;
  11.     fstream f;
  12.     int icount = 0;
  13.     int ibuf = 0;
  14.     cout << "Wie viele Zahlen möchten sie eingeben?" << endl;
  15.     cin >> icount;
  16.     cout << "Bitte " << icount << " Zahlen eingeben" << endl;
  17.     for (int i = 0; i < icount; i++)
  18.     {
  19.         cin >> ibuf;
  20.         v.push_back(ibuf);
  21.     }
  22.     cout << "Schreibe in Testdatei" << endl;
  23.     f.open("Testdatei.txt", fstream::out);
  24.     for (unsigned int i = 0; i < v.size(); i++)
  25.     {
  26.         f << (int)v.at(i) << " ";
  27.     }
  28.     f.sync();
  29.     f.close();
  30.     cout << "Datei geschrieben" << endl;
  31.     cout << "Testdatei wird eingelesen" << endl;
  32.     vector<int> v2;
  33.     fstream f2;
  34.     f2.open("Testdatei.txt", fstream::in);
  35.     while(f2 >> ibuf)
  36.     {
  37.         v2.push_back(ibuf);
  38.     }
  39.     f2.close();
  40.     cout << "Eingelesener Inhalt:" << endl;
  41.     for (unsigned int i = 0; i < v2.size(); i++)
  42.     {
  43.         cout << (int)v2.at(i) << " ";
  44.     }
  45.  
  46.  
  47.     cin.sync();
  48.     cin.get();
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement