I have two question :
-
I have a data on binary file. I want read first 8 bytes to signed long int by using read function but I could not . Do you know how can I do that ?
-
How can directly read a block of data to string ?
Can I read like as shown in
ex :ifstream is; is.open ("test.txt", ios::binary ); string str ; is. read ( str.c_str, 40 ) ; // 40 bytes should be read
Don’t assume
longis wide enough, it often isn’t.long longis guaranteed to be at least 8 bytes wide, though:Mind you, this is still incredibly non-portable due to varying integer sizes and endiannesses.
As for your second question, try
or, safer