Click here to Skip to main content
15,912,756 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Deletion of Pointers in ClistCtrl Data Pin
David Crow7-Sep-04 9:54
David Crow7-Sep-04 9:54 
GeneralRe: Deletion of Pointers in ClistCtrl Data Pin
Cedar Sith7-Sep-04 10:33
Cedar Sith7-Sep-04 10:33 
GeneralRe: Deletion of Pointers in ClistCtrl Data Pin
Ryan Binns7-Sep-04 18:22
Ryan Binns7-Sep-04 18:22 
GeneralRe: Deletion of Pointers in ClistCtrl Data Pin
Cedar Sith8-Sep-04 9:24
Cedar Sith8-Sep-04 9:24 
GeneralRe: Deletion of Pointers in ClistCtrl Data Pin
Ryan Binns8-Sep-04 13:47
Ryan Binns8-Sep-04 13:47 
GeneralRe: Deletion of Pointers in ClistCtrl Data Pin
Cedar Sith8-Sep-04 14:15
Cedar Sith8-Sep-04 14:15 
GeneralRe: Deletion of Pointers in ClistCtrl Data Pin
Cedar Sith7-Sep-04 12:25
Cedar Sith7-Sep-04 12:25 
GeneralSTL / elegant file input (basic question!) Pin
LiquidEyes7-Sep-04 8:03
LiquidEyes7-Sep-04 8:03 
At the moment I'm trying to make an effort to use std::string and std::ifstream in my work, instead of using "stdio.h". My main objective is to write elegant code -- performance is not an issue! Smile | :)

I need to read a lot of blocks (of various sizes) from file, and append them to various string buffers. The problem is that functions like ifstream::read are designed to read into char* style buffers, not strings; however there seems to be some kind of relationship between streambufs and strings that I figured might make my life easier...? Confused | :confused:

using namespace std;
...
string mystring;
ifstream inputfile;
int length = 20;
...
// is there a better way to do this...?
char* buffer = new char [length];
inputfile.read (buffer, length);
mystring += buffer;
delete[] buffer;

// this isn't much better...
char ch;
for (int i=0; i<length; i++)
{
    inputfile >> ch;
    mystring += ch;

    // presumably I could reserve extra space before the loop,
    // to avoid repeated resizing of the string...?
}

I have the gut feeling that there must be a really elegant way to do this, using some combination of streambuf / ifstream::operator>> / ifstream::read etc. I figured the whole point of using std::string was that it can worry about the allocation side of things behind the scenes. However I'm finding the documentation a little cryptic and generalised. Unsure | :~

Any ideas?

It's quite possible I just want the moon on a stick and I should go back to BASIC... Smile | :)
GeneralRe: STL / elegant file input (basic question!) Pin
Ryan Binns7-Sep-04 18:32
Ryan Binns7-Sep-04 18:32 
GeneralRe: STL / elegant file input (basic question!) Pin
LiquidEyes7-Sep-04 23:03
LiquidEyes7-Sep-04 23:03 
GeneralRe: STL / elegant file input (basic question!) Pin
Kevin McFarlane8-Sep-04 2:14
Kevin McFarlane8-Sep-04 2:14 
GeneralRe: STL / elegant file input (basic question!) Pin
LiquidEyes8-Sep-04 2:21
LiquidEyes8-Sep-04 2:21 
GeneralRe: STL / elegant file input (basic question!) Pin
Kevin McFarlane8-Sep-04 6:43
Kevin McFarlane8-Sep-04 6:43 
GeneralRe: STL / elegant file input (basic question!) Pin
Ryan Binns8-Sep-04 3:55
Ryan Binns8-Sep-04 3:55 
GeneralRe: STL / elegant file input (basic question!) Pin
LiquidEyes8-Sep-04 4:10
LiquidEyes8-Sep-04 4:10 
GeneralRe: STL / elegant file input (basic question!) Pin
Ryan Binns8-Sep-04 4:28
Ryan Binns8-Sep-04 4:28 
Generalwhy rebuilding the proj failed eventhough it was running before. Pin
pnpfriend7-Sep-04 7:57
pnpfriend7-Sep-04 7:57 
GeneralRe: why rebuilding the proj failed eventhough it was running before. Pin
David Crow7-Sep-04 9:00
David Crow7-Sep-04 9:00 
GeneralRe: why rebuilding the proj failed eventhough it was running before. Pin
pnpfriend8-Sep-04 6:57
pnpfriend8-Sep-04 6:57 
GeneralCan't have a child window in the non-client area painting itself Pin
DaFrawg7-Sep-04 7:04
DaFrawg7-Sep-04 7:04 
Generalembedded activex Pin
s3b07-Sep-04 6:34
s3b07-Sep-04 6:34 
Generalsearching a grid vector Pin
webmanc7-Sep-04 5:17
webmanc7-Sep-04 5:17 
QuestionSpell Checker API? Pin
Steve Schaneville7-Sep-04 5:10
professionalSteve Schaneville7-Sep-04 5:10 
AnswerRe: Spell Checker API? Pin
Steve Schaneville7-Sep-04 5:20
professionalSteve Schaneville7-Sep-04 5:20 
AnswerRe: Spell Checker API? Pin
David Crow7-Sep-04 5:49
David Crow7-Sep-04 5:49 

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.