Results 1 to 4 of 4
Thread: C++
Hybrid View
-
14th January 2012 16:32 #1
C++
?
Code:#include <iostream> #include <fstream> using namespace std; int main() { int aray[5] = { 1, 2, 3, 4, 5 }; fstream outfile; outfile.open("file", ios::binary | ios::out); for(int i=0; i<5; i++) { outfile.write((char*) &aray[i], sizeof(int)); } outfile.close(); outfile.open("file", ios::binary | ios::ate); for(int i=0; i<5; i++) { outfile.seekp(ios::end - (i+1)*sizeof(int)); outfile.write((char*) &aray[i], sizeof(int)); } outfile.close(); ifstream infile; infile.open("file", ios::binary | ios::in); for(int i=0; i<5; i++) { if(infile.read((char*) &aray[i], sizeof(int))) cout << "True!\n"; else cout << "False!\n"; } for(int i=0; i<5; i++) { cout << aray[i] << ' '; } return 0; }
-
14th January 2012 16:46 #2
open - , , .
, seekp() - , , ..Code:ios::binary | ios::in | ios::out
Code:seekp( - (i+1)*sizeof(int), ios::end);
, . .
"640K ught to be enough for anybody" - Bill Gates, 1981
::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel
-
14th January 2012 16:53 #3
-
14th January 2012 17:58 #4
-?
tellp() seekp()-?, . .
"640K ught to be enough for anybody" - Bill Gates, 1981
::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel




Reply With Quote
* ...

Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in