Is it possible at all to read a binary file larger than 2GB on a 32-
bit system? I tried the following:
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[]) {
fstream fsBin;
fsBin.open(argv[1], fstream::in | fstream::binary );
if (! fsBin) {
cerr << "File " << argv[1] << " cannot be opened.\n";
exit(1);
}
fsBin.close();
return 0;
}
When I ran this program to open a file of 4.4GB size, I got: "File foo
cannot be opened."
Help? Thanks!
-Joe 6 3749 co******@gmail. com wrote:
Is it possible at all to read a binary file larger than 2GB on a 32-
bit system? I tried the following:
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[]) {
fstream fsBin;
fsBin.open(argv[1], fstream::in | fstream::binary );
if (! fsBin) {
cerr << "File " << argv[1] << " cannot be opened.\n";
exit(1);
}
fsBin.close();
return 0;
}
When I ran this program to open a file of 4.4GB size, I got: "File foo
cannot be opened."
I'm afraid that's off-topic here. You will need to use
platform-specific APIs.
Ask yourself "Would the answer be the same if I changed languages?" If
so, then you're platform or algorithm specific, rather than C++ specific.
Similarly, ask, "Does this question even make sense if I change
platforms?" If not, then you're platform specific.
Your question fails both tests, and in fact, your post makes it clear
it's platform specific (32-bit system).
See http://www.parashift.com/c++-faq-lit...t.html#faq-5.9 for
list of possible newsgoups. co******@gmail. com wrote:
Is it possible at all to read a binary file larger than 2GB on a 32-
bit system?
Depends on the system and the C++ library implementation.
I tried the following:
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[]) {
fstream fsBin;
fsBin.open(argv[1], fstream::in | fstream::binary );
if (! fsBin) {
cerr << "File " << argv[1] << " cannot be opened.\n";
exit(1);
}
fsBin.close();
return 0;
}
When I ran this program to open a file of 4.4GB size, I got: "File foo
cannot be opened."
Help? Thanks!
You have to query the system for the reasons. I am not sure how to do
that portably. And keep in mind that the implementation you're using
may not be capable of dealing with large files. If that's so, you will
have to resort to the OS-specific ways, for example, on Windows there
are 'CreateFile' and 'ReadFile' API calls.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
You are right. I have copied my post to comp.unix.progr ammer. Sorry
(it seems I cannot remove my post)!
-Joe co******@gmail. com writes:
Is it possible at all to read a binary file larger than 2GB on a 32-
bit system? I tried the following:
One trick I've used to do this is to read it from a pipe:
cat file |./your_program
This will work fine with a text file (at least with any reasonable
version of cat).
The reason large files require special support is because the seek
pointer needs to be large enough to address the entire file. But
since pipes aren't seekable, this restriction doesn't apply.
Good luck!
----Scott.
On Oct 4, 4:54 am, coold...@gmail. com wrote:
Is it possible at all to read a binary file larger than 2GB on a 32-
bit system? I tried the following:
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[]) {
fstream fsBin;
fsBin.open(argv[1], fstream::in | fstream::binary );
if (! fsBin) {
cerr << "File " << argv[1] << " cannot be opened.\n";
exit(1);
}
fsBin.close();
return 0;
}
When I ran this program to open a file of 4.4GB size, I got: "File foo
cannot be opened."
Help? Thanks!
-Joe
in linux after 2.4.18 you can open the file with O_LARGEFILE flag,and
use lseek,read...
use "man lseek" to see the details This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Guyon Morée |
last post by:
what is the difference?
if I open a text file in binary (rb) mode, it doesn't matter... the read()
output is the same.
|
by: Michael Van Altena via .NET 247 |
last post by:
I'm trying to figure out how to read a formatted binary file intoa structure definition in C#. I've tried using the"StructLayout" attribute with both LayoutKind.Explicit andLayoutKind.Sequential options. I can get this to worksuccessfully, but only when I'm NOT dealing with arrays in thestructure definition.
For example: In C, you are able to simply read a binary file intoa structure as follows:
...
|
by: KantKwitDansin1 |
last post by:
I have a file "a.dat" containing 10^4 32 bit binary numbers. I need to
read in these numbers and deterimine if they are prime. The primality
part I will have to figure out later, but I was wondering if there is
anyone out there that can help me in reading in the binary numbers.
Basically, read in 32 bits and thats
the first number, read in another 32 bits and thats the 2nd
number, etc. Is is something like this?
fread(char, sizeofchar,...
|
by: spike |
last post by:
Im trying to write a program that should
read through a binary file searching for the character sequence "\name\"
Then it should read the characters following the "\name\" sequence
until a NULL character is encountered.
But when my program runs it gets a SIGSEGV (Segmentation vioalation) signal.
Whats wrong?
And is there a better way than mine to solve this task (most likely)
|
by: QQ |
last post by:
I am trying to read data from Excel files
I use the following codes, however, it didn't work
Can anyone tell me what the format excel files have, what I should do
to read it
from C?
Thanks a lot!
#include <stdio.h>
| |
by: Ching-Lung |
last post by:
Hi all,
I try to create a tool to check the delta (diff) of 2
binaries and create the delta binary. I use binary
formatter (serialization) to create the delta binary. It
works fine but the delta binary is pretty huge in size. I
have 1 byte file and 2 bytes file, the delta should be 1
byte but somehow it turns out to be 249 bytes using binary
formatter. I guess serialization has some other things
added to the delta file.
|
by: Patient Guy |
last post by:
Has anyone written code that successfully manipulates binary file data
using Javascript?
It might---and in the case of doing I/O, will---make use of browser-
specific functions (ActiveX/COM with Internet Explorer, XPCOM/XPConnect
with Mozilla/Firefox).
I am writing client-side code that will generate binary data for producing
a GIF file through an OBJECT element. (The GIF is an image of a line and
points on a two-axis plot.)
|
by: Hallvard B Furuseth |
last post by:
I'm trying to clean up a program which does arithmetic on text
file positions, and also reads text files in binary mode. I
can't easily get rid of it all, so I'm wondering which of the
following assumptions are, well, least unportable.
In particular, do anyone know if there are real-life systems
where the text file assumptions below don't hold?
For text mode FILE*s,
|
by: Atos |
last post by:
Binary search is used to locate a value in a sorted list of values.
It selects the middle element in the array of sorted values, and compares it with the target value; that is the key we are searhing for in the array.
If it islower than the target value then the search is made after that middle element and till the end of the array. If it is equal then the target value is found and the middle is returned. Otherwise, search is made from the...
|
by: zl2k |
last post by:
hi, there
I have a appendable binary file of complex data structure named
data.bin created by myself. It is written in the following format:
number of Data, Data array
Suppose I have following data.bin (3 Data appended to 2 Data):
2, data0, data1, 3, data0, data1, data2
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |