codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <iostream> #include <sstream> using namespace std; struct test { int x; int y; }; int main() { int i; const int size = 5; test arr[size]; test tmp; for(i = 0; i < size; ++i) { cout << "Enter x: "<<(arr[i].x = i)<<endl; //cin >> arr[i].x; cout << "Enter y: "<<(arr[i].y = i)<<endl; //cin >> arr[i].y; cout << "\n"; } // запись массива в файл stringstream ss; for(i = 0; i < size; ++i) { ss.write((char*)(&arr[i]), sizeof(test)); } ss.clear(); ss.seekg(0, ios::beg); // чтение из файла одной записи ss.seekg(-3 * sizeof(tmp), ios::end); ss.read((char*)(&tmp), sizeof(test)); cout << "x: " << tmp.x << " y: " << tmp.y << "\n"; ss.seekg(2 * sizeof(tmp), ios::beg); ss.read((char*)(&tmp), sizeof(test)); cout << "x: " << tmp.x << " y: " << tmp.y << "\n"; ss.clear(); return 0; }
Private
[
?
]
Run code
Submit