![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Hobbyist Programmer
Join Date: Mar 2006
Location: Lebanon
Posts: 148
Rep Power: 3
![]() |
Memory problem
Im trying to read a char * from an input text file.
char* video=new char[10000]; ifstream getvid (file); getvid>>video; getvid.close(); if the size of the bitstream was lets say 50. there would be no problem wiht the code. but if i initialize : Quote:
how do i avoid this problem if i dont want to give a very large number for initializing the file video. lets say the bitstream was as big as a megabyte. and i want to read it into video, there is a limit to how big the constant in char[constant] is. so whats is the solution. |
|
|
|
|
|
|
#2 |
|
Hobbyist
Join Date: Sep 2005
Posts: 266
Rep Power: 4
![]() |
Open the stream in binary mode, and use tellg() to first get the size of the file.
|
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Mar 2006
Location: Lebanon
Posts: 148
Rep Power: 3
![]() |
were can i read about binary mode, i know nothing about it..?
|
|
|
|
|
|
#4 |
|
Programmer
Join Date: Apr 2006
Location: Calgary, Alberta
Posts: 67
Rep Power: 3
![]() |
Just google "Binary I/O C++" and there should be a crap load of pages on the subject
|
|
|
|
|
|
#5 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Google "binary I/O"?? All I/O is binary I/O. It's all a stream of 1s and 0s. Text mode, which is strictly a windows thangy, has to do with adding extra binary characters that you wouldn't normally expect to be added. They play some hob with seek and tell operations. Text is just binary I/O that is expected to be interpreted in some 'different' way, nothing to do with the mode, per se. That is, if it's ASCII, 61 is interpreted as lower-case 'a', rather than decimal 61. 'S'all the same as far as the I/O is concerned, it doesn't know or care. Once you realize this and don't let it buffalo you, you shouldn't have any problems using any of the mechanisms.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|