Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // filestream.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- using namespace std;
- int _tmain(int argc, _TCHAR* argv[])
- {
- vector<int> v;
- fstream f;
- int icount = 0;
- int ibuf = 0;
- cout << "Wie viele Zahlen möchten sie eingeben?" << endl;
- cin >> icount;
- cout << "Bitte " << icount << " Zahlen eingeben" << endl;
- for (int i = 0; i < icount; i++)
- {
- cin >> ibuf;
- v.push_back(ibuf);
- }
- cout << "Schreibe in Testdatei" << endl;
- f.open("Testdatei.txt", fstream::out);
- for (unsigned int i = 0; i < v.size(); i++)
- {
- f << (int)v.at(i) << " ";
- }
- f.sync();
- f.close();
- cout << "Datei geschrieben" << endl;
- cout << "Testdatei wird eingelesen" << endl;
- vector<int> v2;
- fstream f2;
- f2.open("Testdatei.txt", fstream::in);
- while(f2 >> ibuf)
- {
- v2.push_back(ibuf);
- }
- f2.close();
- cout << "Eingelesener Inhalt:" << endl;
- for (unsigned int i = 0; i < v2.size(); i++)
- {
- cout << (int)v2.at(i) << " ";
- }
- cin.sync();
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement