Click here to Skip to main content
16,007,885 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralFILE IO Pin
demasoni.com27-May-04 14:42
demasoni.com27-May-04 14:42 
GeneralRe: FILE IO Pin
Anthony_Yio27-May-04 16:50
Anthony_Yio27-May-04 16:50 
GeneralRe: FILE IO Pin
demasoni.com27-May-04 19:21
demasoni.com27-May-04 19:21 
GeneralRe: FILE IO Pin
Anthony_Yio27-May-04 19:44
Anthony_Yio27-May-04 19:44 
GeneralRe: FILE IO Pin
demasoni.com28-May-04 11:57
demasoni.com28-May-04 11:57 
GeneralRe: FILE IO Pin
toxcct27-May-04 21:41
toxcct27-May-04 21:41 
GeneralRe: FILE IO Pin
markkuk27-May-04 22:59
markkuk27-May-04 22:59 
GeneralRe: FILE IO Pin
demasoni.com28-May-04 3:55
demasoni.com28-May-04 3:55 
markkuk said...
Why are you reading the file twice and throwing away the bytes read in the first pass? Here's a function to read all the bytes of a file in one pass to a C++ std::vector.

That was when I was new to C#. I was making the first pass to get the actual number bytes in the file so I could use it to fill dynamic arrays with each character. I did not know at that time what method or call was used to get the size. Yes, I knew before I placed the code on this thread that it is a waste of time to read a file twice. I do know C# now, and I know console C++. Just a couple of days ago I have migrated to VC++MFC which I am still a little bit new at, your help is greatly appreciated. Smile | :)

Thanks markkuk,

Interesting function you have.

Vector is a STL container. You are passing both the "file_path_and_name" and the vector named buffer by reference so it is a void function. You also used a typedef.

So within the main program you could...

vector<BYTE> BufferNumberOne;
readFile("C:\files\picture1.jpg", BufferNumberOne);
for (int a = 0; a < BufferNumberOne.size(); a++)
{
BufferNumberOne[a];
//do stuff like fill array, modify chars, or etc.
}

or would you...

String some_file = "C:\files\picture1.jpg";

vector<BYTE> BufferNumberOne;
readFile(some_file, BufferNumberOne);
for (int a = 0; a < BufferNumberOne.size(); a++)
{
BufferNumberOne[a];
//do stuff like fill array, modify chars, or etc.
}

Please quote me if I am wrong on any of the above statements.

In past C++ courses we used statement like while(!EOF) but EOF is char 26, ^Z and it exists many times within jpg or other such file types that use any or all of the 256 different characters. Not many C++ text books discuss methods in any detail at all on how to read files of types other than txt.

Thanks Much markkuk,

demasoni.com





Elite
GeneralRe: FILE IO Pin
markkuk28-May-04 12:19
markkuk28-May-04 12:19 
GeneralRe: FILE IO Pin
demasoni.com30-May-04 8:23
demasoni.com30-May-04 8:23 
GeneralActiveX licensing Pin
mirano27-May-04 12:27
mirano27-May-04 12:27 
GeneralTab Key Pin
Grahamfff27-May-04 12:26
Grahamfff27-May-04 12:26 
GeneralRe: Tab Key Pin
Anthony_Yio27-May-04 17:27
Anthony_Yio27-May-04 17:27 
GeneralRe: Tab Key Pin
Ryan Binns27-May-04 18:33
Ryan Binns27-May-04 18:33 
GeneralRe: Tab Key Pin
sweep12328-May-04 0:34
sweep12328-May-04 0:34 
GeneralRe: Tab Key Pin
Ryan Binns28-May-04 0:46
Ryan Binns28-May-04 0:46 
GeneralRe: Tab Key Pin
Anthony_Yio28-May-04 19:10
Anthony_Yio28-May-04 19:10 
GeneralRe: Tab Key Pin
Ryan Binns29-May-04 3:41
Ryan Binns29-May-04 3:41 
GeneralCreateProcessWithLogonW Pin
cobyjone27-May-04 10:25
cobyjone27-May-04 10:25 
GeneralRe: CreateProcessWithLogonW Pin
Rob Manderson27-May-04 12:41
protectorRob Manderson27-May-04 12:41 
GeneralRe: CreateProcessWithLogonW Pin
cobyjone28-May-04 3:48
cobyjone28-May-04 3:48 
GeneralChanging Size Font and Vertical Scroll Bar Pin
Eversman27-May-04 10:16
Eversman27-May-04 10:16 
GeneralRe: Changing Size Font and Vertical Scroll Bar Pin
gUrM33T27-May-04 15:07
gUrM33T27-May-04 15:07 
GeneralUsing Excel data in VC++ 6.0 Pin
greg8927-May-04 9:31
greg8927-May-04 9:31 
GeneralRe: Using Excel data in VC++ 6.0 Pin
Anthony_Yio27-May-04 17:47
Anthony_Yio27-May-04 17:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.