Search
 
SCRIPT & CODE EXAMPLE
 

CPP

read large files part by part in C++

// Buffer size 1 Megabyte (or any number you like)
size_t buffer_size = 1<<20;
char *buffer = new char[buffer_size];

std::ifstream fin("input.dat");

while (fin)
{
    // Try to read next chunk of data
    fin.read(buffer, buffer_size);
    // Get the number of bytes actually read
    size_t count = fin.gcount();
    // If nothing has been read, break
    if (!count) 
        break;
    // Do whatever you need with first count bytes in the buffer
    // ...
}

delete[] buffer;
Comment

PREVIOUS NEXT
Code Example
Cpp :: decising how many numbers after comma c++ 
Cpp :: C++ thread header 
Cpp :: ‘npos’ is not a member of ‘std’ 
Cpp :: 7 9 C:UsersAliyahDocumentsshut up.cpp [Error] expected unqualified-id before string constant 
Cpp :: inbuilt function for bin to dec in c++ 
Cpp :: std::throw_with_nested 
Cpp :: C++ if...else Statement 
Cpp :: how to delay text in c++ console app 
Cpp :: +++++++++ 
Cpp :: random 1 diem tren man hinh bang dev c 
Cpp :: deadlock detection in c++coding ninjas 
Cpp :: cpp qmenu add custom widget action 
Cpp :: constant qualifier c++ "error display" 
Cpp :: C++ Enumeration Type 
Cpp :: c++ power operator 
Cpp :: return value optimization example 
Cpp :: c++ const shared_ptr 
Cpp :: executing linux scripts 
Cpp :: how to initialize a vector in c++ 
Cpp :: c++ remove last element from array 
Cpp :: how to parse using stringstream 
Cpp :: are arrays faster than vectors c++ 
Cpp :: frequency of characters in a string in c++ 
Cpp :: c++ short hand if else 
C :: how to create random integers from a specific range in c language 
C :: factorial c program using for loop 
C :: golden cobblestone modpack 
C :: add border to image android 
C :: postgres random select 
C :: c language append line to file 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =