Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
L

LiquidEyes

@LiquidEyes
About
Posts
7
Topics
3
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • istream: seekg / tellg, peculiar behaviour
    L LiquidEyes

    I'm having two istream-related problems. Please can somebody help... :confused: Problem 1

    void loadStuffFromStream (istream& stream)
    {
    	// goes too far!!
    	stream.seekg( length, ios_base::cur );
    }
    

    ***edited*** This seems to skip to an arbitrary position in the stream, instead of 'current position' + length bytes. Why does it do this? Problem 2

    char ch;
    int pos;
    ...
    pos = stream.tellg();		// now pos=0
    stream.get (ch);
    pos = stream.tellg();		// now pos=3585 ???
    stream.get (ch);
    pos = stream.tellg();		// now pos=3586
    stream.get (ch);
    pos = stream.tellg();		// now pos=3587
    stream.get (ch);
    // etc...
    

    Not so much a 'problem' as a matter of curiosity. Why is there a sudden leap in the read-position reported by tellg the first time I read from the stream? (N.B. It is reading the correct characters into ch!)

    C / C++ / MFC help question

  • STL / elegant file input (basic question!)
    L LiquidEyes

    You'll have to use the read() method of ifstream to do that. Precisely. Which takes us back to my original question ... what structure can I read into instead of an old fashioned char* array? I just thought there might be an elegant way, using vectors or strings or something, that didn't involve allocating chars manually. As I said, maybe I just want the moon on a stick. :)

    C / C++ / MFC help question c++ performance

  • STL / elegant file input (basic question!)
    L LiquidEyes

    I don't want it to stop on 'newline'. I want it to read a fixed number of bytes. :confused:

    C / C++ / MFC help question c++ performance

  • STL / elegant file input (basic question!)
    L LiquidEyes

    Thanks for the reply. However I don't see how it will know to stop after (say) 20 characters? Without a delimeter, will it read the whole file into the string? I want to do the STL equivalent of fread( mystring, sizeof(char), length, inputfile ); or failing that, use something more elegant than a char[] (which I have to allocate myself) as an intermediate buffer.

    C / C++ / MFC help question c++ performance

  • STL / elegant file input (basic question!)
    L LiquidEyes

    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! :) 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: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. :~ Any ideas? It's quite possible I just want the moon on a stick and I should go back to BASIC... :)

    C / C++ / MFC help question c++ performance

  • Visual C++ Toolkit: optimizing or not?
    L LiquidEyes

    Kewl. Thanks for the info. Given that I'm not interested in the other languages, is there anything else about .NET Professional I should be particularly interested in? MS seem to imply that it has superior debugging facilities compared with the Standard edition, but if we're just talking fancy-pants stuff like remote debugging and such-like, then I'm not too fussed. I just want to write Visual C++ apps on my home PC (ultimately, with a view to distributing my apps). I use .NET Pro at work, so I'm wondering whether, when I buy C++ .NET Standard for home use, I'm suddenly going to realise there are a load of missing features that I badly want! :)

    C / C++ / MFC c++ csharp question

  • Visual C++ Toolkit: optimizing or not?
    L LiquidEyes

    I understand that Microsoft are now giving their Visual C++ Toolkit away for free. :cool: Some websites claim that the compiler is equivalent to the Standard C++ compiler (i.e. not optimizing). On the other hand, Microsoft claim the compiler is the same as their Professional compiler. This seems too good to be true! :omg: Surely one of the main incentives for purchasing .NET Professional is that you get an optimizing compiler? :confused: In other words, what's to stop me just buying C++ .NET Standard (which comes pretty cheap) and, when I've finished developing my app, using the free toolkit to build the final, optimized, distributable exe? In a nutshell: what's the catch? :~

    C / C++ / MFC c++ csharp question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups