http://groups.google.com/group/comp.lang.c++?hl=en
comp.lang.c++@googlegroups.com
Today's topics:
* Erase map item via a const_iterator - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/9e8b3cac7f8c6976?hl=en
* Why am I so stupid? - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/9c35ffbaed42a937?hl=en
==============================================================================
TOPIC: Erase map item via a const_iterator
http://groups.google.com/group/comp.lang.c++/t/9e8b3cac7f8c6976?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Jun 3 2009 11:46 pm
From: none
Alf P. Steinbach wrote:
> - Alf (if you delete an 'e', and type an 'e' again, is it the same
> 'e', eh?)
No joke, I have had that exact same thought. It is probably a sign that I
am completely insane, but I have even followed the train of thought
further...
If I select/cut/paste an 'e', is it the same 'e'?
If I delete an 'e' and then "undo" the deletion, is it more the same 'e'
than it would have been if I had typed a new 'e'?
I understand every step that happens from the instant when the metal
contacts under my 'e' key touch each other to the dispatch of the
WM_KEYDOWN message to the application. Yet, somehow, I can't convince
myself that when you delete that 'e' and type a new one, it is the same
'e'.
Related question: If I gave you a rock composed of 10^20 atoms, along with
a list of every atom's exact <x,y,z> position in space, then destroyed that
rock completely, and then reassembled it to so that every atom's new
<x,y,z> was the same as it was originally, would it be the same rock?
==============================================================================
TOPIC: Why am I so stupid?
http://groups.google.com/group/comp.lang.c++/t/9c35ffbaed42a937?hl=en
==============================================================================
== 1 of 2 ==
Date: Wed, Jun 3 2009 11:50 pm
From: "Alf P. Steinbach"
* none:
> Every little thing I try to do using STL turns into a five mile crawl
> through raw sewage.
>
> I want to use the STL to lex/parse some text. This must have been done
> at least 5.0e+75 times before, but I can't find the solution in the FAQ
> or in any examples.
>
> This is my utterly failed attempt:
>
>
> std::string s = "5.0 This is a string";
> std::istringstream i(s);
> std::cout << "Before: \"" << s << "\"" << std::endl;
>
> float x;
> i >> x;
>
> std::cout << "Extracted a float: " << x << std::endl;
> std::cout << "After: \"" << s << "\"" << std::endl;
>
>
> And this is the output produced:
>
>
> Before: "5.0 This is a string"
> Extracted a float: 5
> After: "5.0 This is a string"
>
>
> All that I want in this world is for that output to be, instead, this:
>
>
> Before: "5.0 This is a string"
> Extracted a float: 5
> After: " This is a string"
>
>
> Then I can just continue parsing the remainder of the string.
All you need to do is to continue to read from the istringstream (e.g. if you
really wanted to you could read the remainding text into the string by 'getline(
i, s );', but note that doing that thing repeatedly would yield O(n^2) time).
The stream does not change the original string from which it is initialized.
It just changes its internal buffer read position.
> I have
> tried the following, and all have failed:
>
> 1) Making the assignment "s = i.str();" after the line "i >> x;" in
> hopes that "i.str()" would return only the un-extracted portion of the
> string. It doesn't. It returns the entire string.
> 2) Calling "i.sync();" I don't know why I thought this would help. A
> shot in the dark.
> 3) Calling "i.ignore();" a few times. No effect.
> 4) Changing the last line to:
>
> std::cout << "After: \"" << i << "\"" << std::endl;
>
> (displaying the value of "i" instead of "s". It displays a hex number,
> probably a pointer I guess.
>
> 5) Changing the last line to:
>
> std::cout << "After: \"" << i.str() << "\"" << std::endl;
>
> I knew before I tried that it wouldn't help, but was desperate.
>
>
> How do you get the >> operator to actually remove the characters from a
> string?
It removes characters from the input buffer. :-)
> Help me, Obi Wan. You're my only hope.
>
>
> P.S.: Please, oh please, don't say Boost. I don't want to add 75000
> files to my project just to remove three characters from a string.
Boost isn't a bad idea: it should be there anyway.
The problem with Boost is that, as you rightly note, it's an extreme amount of
baggage for just a small kernel of functionality that you regularly use.
And even though that's about the same as with many other libraries, one does
wish for some "Boost kernel" project...
Cheers & hth.,
- Alf
--
Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
No ads, and there is some C++ stuff! :-) Just going there is good. Linking
to it is even better! Thanks in advance!
== 2 of 2 ==
Date: Thurs, Jun 4 2009 12:14 am
From: none
Alf P. Steinbach wrote:
> All you need to do is to continue to read from the istringstream
I Can't really do that. Maybe there is a way, but it's not obvious. To
write a lexer, you need lots of little functions like "lex_float" and
"lex_int" and so on. Some of these functions rely on members of
std::string, like "find_first_of" and "find_first_not_of," etc. So the
text that's being parsed really needs to exist in a string, not an
istringstream. Each individual function can create an istringstream as a
helper, as in my example code, but the input itself needs to be in a
string.
> if you really wanted to you could read the remainding text into the
> string by 'getline( i, s );', but note that doing that thing
> repeatedly would yield O(n^2) time).
This works! Many many thanks. Execution speed for a lexer isn't really
critical, but it needs to be reasonably efficient when large files are used
as input. I am open to other suggestions!
> Boost isn't a bad idea: it should be there anyway.
>
> The problem with Boost is that, as you rightly note, it's an extreme
> amount of baggage for just a small kernel of functionality that you
> regularly use.
>
> And even though that's about the same as with many other libraries,
> one does wish for some "Boost kernel" project...
Ugh. Boost. I have used it many times, and have developed a distaste for
it. Maybe the thing that would make it more friendly would be to split it
up. If all I want is boost::format, for "printf" functionality, then give
me a little package I can download that includes just that. I suppose the
problem is that boost::format relies on a hundred other boost functions and
classes. I don't know the solution.
Anyway, thanks again for the help.
==============================================================================
You received this message because you are subscribed to the Google Groups "comp.lang.c++"
group.
To post to this group, visit http://groups.google.com/group/comp.lang.c++?hl=en
To unsubscribe from this group, send email to comp.lang.c+++unsubscribe@googlegroups.com
To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c++/subscribe?hl=en
To report abuse, send email explaining the problem to abuse@googlegroups.com
==============================================================================
Google Groups: http://groups.google.com/?hl=en
No comments:
Post a Comment