Click here to Skip to main content
15,924,196 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: whats wrong with this? Pin
Christian Graus5-Apr-02 0:33
protectorChristian Graus5-Apr-02 0:33 
GeneralRe: whats wrong with this? Pin
jan larsen5-Apr-02 2:57
jan larsen5-Apr-02 2:57 
AnswerRe: whats wrong with this? Pin
alex.barylski4-Apr-02 23:34
alex.barylski4-Apr-02 23:34 
AnswerRe: whats wrong with this? Pin
Christian Graus4-Apr-02 23:46
protectorChristian Graus4-Apr-02 23:46 
GeneralRe: whats wrong with this? Pin
Mazdak4-Apr-02 23:55
Mazdak4-Apr-02 23:55 
GeneralRe: whats wrong with this? Pin
Christian Graus5-Apr-02 0:07
protectorChristian Graus5-Apr-02 0:07 
GeneralRe: whats wrong with this? Pin
Mazdak5-Apr-02 0:19
Mazdak5-Apr-02 0:19 
GeneralRe: whats wrong with this? Pin
Christian Graus5-Apr-02 0:30
protectorChristian Graus5-Apr-02 0:30 
I thought about it in the shower - don't use std::string, use a vector of unsigned chars instead. I have an article on vector, it's the first of my STL articles.

Basically you want to use an ifstream to read a file, and push the result into a vector. Like this:

This needs you to include fstream, vector, algorithm, iostream and maybe functional. I tacked it on the end of an existing project to test it. Give it the name of a real file, and it will read the file into the vector and then print it out to the console. Ignore the last line and the rest will give you a vector, which you can access with array notation, as in vec[0] = 5, etc. And it does not require you know before hand how big the file is, although knowing and preallocating the space in the vector would be an optimisation, as it stands, no MFC is required, nor do you need to manage any memory.

std::ifstream file("c:\\boot.ini");

std::vector<char> vec;

std::copy(std::istream_iterator<char>(file),std::istream_iterator<char>(), std::back_inserter(vec));

std::copy(vec.begin(), vec.end(), std::ostream_iterator<char>(cout, ""));

Christian

The tragedy of cyberspace - that so much can travel so far, and yet mean so little.

"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- <b>Jon Hulatt, 22/3/2002</b>

GeneralRe: whats wrong with this? Pin
Mazdak5-Apr-02 0:59
Mazdak5-Apr-02 0:59 
GeneralRe: whats wrong with this? Pin
Mazdak5-Apr-02 1:46
Mazdak5-Apr-02 1:46 
GeneralRe: whats wrong with this? Pin
Christian Graus5-Apr-02 9:57
protectorChristian Graus5-Apr-02 9:57 
AnswerRe: whats wrong with this? Pin
Jon Hulatt5-Apr-02 5:51
Jon Hulatt5-Apr-02 5:51 
GeneralRe: whats wrong with this? Pin
Mazdak5-Apr-02 6:11
Mazdak5-Apr-02 6:11 
GeneralNetmessagebuffersend(): this is strange! Pin
Jörg Anslik4-Apr-02 21:42
Jörg Anslik4-Apr-02 21:42 
GeneralDirectShow StillCap problem Pin
Ruzicka4-Apr-02 21:37
Ruzicka4-Apr-02 21:37 
Generalbasic_string Pin
Niklas L4-Apr-02 21:37
Niklas L4-Apr-02 21:37 
GeneralRe: basic_string Pin
Niklas L4-Apr-02 21:39
Niklas L4-Apr-02 21:39 
GeneralRe: basic_string Pin
Joaquín M López Muñoz4-Apr-02 22:32
Joaquín M López Muñoz4-Apr-02 22:32 
GeneralRe: basic_string Pin
Joao Vaz4-Apr-02 23:49
Joao Vaz4-Apr-02 23:49 
GeneralRe: basic_string Pin
Tim Smith5-Apr-02 3:48
Tim Smith5-Apr-02 3:48 
GeneralRe: basic_string Pin
Joao Vaz5-Apr-02 4:56
Joao Vaz5-Apr-02 4:56 
GeneralRe: basic_string Pin
Joaquín M López Muñoz5-Apr-02 5:40
Joaquín M López Muñoz5-Apr-02 5:40 
GeneralRe: basic_string Pin
Joao Vaz5-Apr-02 6:03
Joao Vaz5-Apr-02 6:03 
GeneralRe: basic_string Pin
Niklas L5-Apr-02 1:12
Niklas L5-Apr-02 1:12 
GeneralPLEASE HELP ME Pin
cycosi4-Apr-02 21:12
cycosi4-Apr-02 21:12 

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.