Results 1 to 4 of 4

Thread: C++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User thefrozenhell's Avatar
    Join Date: May:2010
    Location:
    Posts: 24

    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;
    }

  2. #2
    ɐ-əpoɔᴉu⋂ ɐ ə anrieff's Avatar
    Join Date: Apr:2004
    Location: Sofia
    Posts: 8,448
    open - , , .

    Code:
    ios::binary | ios::in | ios::out
    , seekp() - , , ..
    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

  3. #3
    Registered User thefrozenhell's Avatar
    Join Date: May:2010
    Location:
    Posts: 24
    * ...

  4. #4
    ɐ-əpoɔᴉu⋂ ɐ ə anrieff's Avatar
    Join Date: Apr:2004
    Location: Sofia
    Posts: 8,448
    -?
    tellp() seekp()-?
    , . .
    "640K ught to be enough for anybody" - Bill Gates, 1981
    ::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |