Thread: Can not read the file, I can not quite help!

  1. #1
    Registered User
    Join Date
    Feb 2015
    Posts
    74

    Can not read the file, I can not quite help!

    Good time day!!
    I welcome all to a nice wonderful forum.


    Code:
     int main(int argc, const char **argv, const char **envp)
    {
    
    
            spilna_pamyat s, *Ps=&s;
    
    
            ZeroMemory(&s, sizeof(s));
    
    
    
    
    
    
    
    
    char* mas =new char[];
    //В цей масив будемо зберігати файл
    
    
    
    
    
    
    
    
      ifstream fs8("test_file_path.txt");
        if (!fs8.is_open()) {
            cout << "Не вдалося відкрити" << "test_file_path.txt" << endl;
            return 0;
        }
    
    
      ifstream dzherelo ( "test_file_path.txt", ios::in | ios::binary);
      ofstream priymach ( "produkt.txt", ios::app | ios::binary);
    
    
      vstavlyannya(22, 666.66, Sui, priymach);



    How to read the file into an array of unknown size, eg
    997,7KBu a prototype and later possibly more.
    You can expect to hihobayta likely. The key word is unknown.
    And under the same file, such test_file_path.txt - it probably bit data items, possibly large amounts
    text encoding UTP-8.


    in prototype and in the future possibly more.
    You can big large, hyhabaytiv likely.




    There is a stream, such as a so


    [code] ifstream dzherelo ( "test_file_path.txt", ios :: in | ios :: binary);
    ofstream priymach ( "produkt.txt", ios :: app | ios :: binary);
    [/code]


    How do I cope with it? More precisely, I had a whole head burned, and I do not understand razumiyu what to do with the flow dzherelo at all, I just can not imagine.
    First, make it somehow to the array? Clearly dynamically allocated array?
    Anyway, I know how long I order it?


    I really want an explanation, but rather all sorts of code samples, links can even link to a professional code.


    I beg you, help please! Waiting for answers!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    This shows you how to read a file into memory, by measuring the size of the file at run time, and allocating memory to hold the file.
    istream::read - C++ Reference
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It's unfortunately also a very poor example. Here's a better one. Take a look at the example at the bottom where it shows how to read an entire file into a string.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-07-2014, 07:01 AM
  2. Replies: 7
    Last Post: 12-07-2012, 10:44 PM
  3. Open a file, read it ... and ... read it again
    By Tiago in forum C Programming
    Replies: 1
    Last Post: 04-17-2010, 03:32 AM
  4. How can I know the actual bytes read in a file read
    By pliang in forum C++ Programming
    Replies: 1
    Last Post: 06-08-2005, 04:23 PM

Tags for this Thread