Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- //Подключаю заголовочный файд для работы с файлами
- #include <fstream>
- //Стандартный неймспейс
- using namespace std;
- int main() {
- //Класс чтения файла
- ifstream InputFile;
- //Открываю файл (для чтения)
- //ВАЖНО! Заранее создать файл с именем in.txt в той же папке,
- //что и файл *.cpp, и заполнить его числами.
- InputFile.open("in.txt");
- //Если файл открыть невозможно, выхожу из программы
- if (!InputFile.is_open()) {
- cerr << "File can't be opened!\n";
- exit(1);
- }
- int n;
- cout << "Enter number of array elements\n";
- cin >> n;
- int *A;
- A = new int(n);
- cout << "Your numbers:\n";
- for (int i=0; i<n; i++) {
- InputFile >> A[i];
- cout << "A[" << i << "] = " << A[i] << endl;
- }
- InputFile.close();
- ofstream OutputFile;
- OutputFile.open("out.bin", ios::binary);
- if (!OutputFile.is_open()) {
- cerr << "File can't be opened!\n";
- exit(1);
- }
- for (int i=0; i<n; i++) {
- OutputFile.write((char*)&A[i], sizeof(A[i]));
- }
- OutputFile.close();
- delete A;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement