Friday, March 9, 2018

Digest for comp.lang.c++@googlegroups.com - 7 updates in 1 topic

legalize+jeeves@mail.xmission.com (Richard): Mar 09 08:35PM

[Please do not mail me a copy of your followup]
 
Bob Langelaan <bobl0456@gmail.com> spake the secret code
 
>[...] if I understand you correctly, you are saying that the
>VC++ result is the correct result?
 
Yes.
 
>Xcode and Clion. I did not want to tell they that their compiler is
>crap without some ammunition. It seems that you have just given me that
>ammunition :)
 
It's not their compiler that's at fault; it is their standard library
that is at fault.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <http://terminals-wiki.org>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
legalize+jeeves@mail.xmission.com (Richard): Mar 09 08:37PM

[Please do not mail me a copy of your followup]
 
Jorgen Grahn <grahn+nntp@snipabacken.se> spake the secret code
 
>Something is wrong here: Clion is not a compiler; it's an IDE. I've
>seen it used on Linux with gcc and clang as backends. IIRC the same
>goes for Xcode.
 
Correct.
 
Which compiler you're using under the hood depends on what's installed
on your system. Typically, installing Xcode also installs the
compiler and the IDE version is matched to a particular compiler
version that it installed. However, the IDE/project can be configured
to use a particular compiler.
 
>It's probably better to first establich which behavior is correct C++.
>(I won't try, since I'm disinterested in parsing text using
>std::istream.)
 
The MSVC implementation is reporting the correct behavior. Extracting
an integer from a stream stops at the first non-digit character in the
stream and returns the integer and leaves the non-digit character
alone for you to consume in a subsequent extraction operation.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <http://terminals-wiki.org>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
Real Troll <Real.Troll@Trolls.com>: Mar 09 05:15PM -0400

On 09/03/2018 17:51, Bob Langelaan wrote:
> With some other compilers, including Xcode and Clion , var will contain the value 0 after the operation and the 'i' will have been swallowed up in the operation as well. In other words, the 'i' will no longer be in the cin buffer. Not sure about the error state of the cin object after the operation.
 
How did you prove that " 'i' will have been swallowed up in the
operation as well. In other words, the 'i' will no longer be in the cin
buffer. "?
 
I tried this in Visual Studio 2017 and Embarcadero Tokyo and both give
me correct result, i.e they give me 12345. However, please tell me how
did you know that i is still in the buffer?
 
Thank you.
Bob Langelaan <bobl0456@gmail.com>: Mar 09 02:32PM -0800

On Friday, March 9, 2018 at 9:52:04 AM UTC-8, Bob Langelaan wrote:
 
> With some other compilers, including Xcode and Clion , var will contain the value 0 after the operation and the 'i' will have been swallowed up in the operation as well. In other words, the 'i' will no longer be in the cin buffer. Not sure about the error state of the cin object after the operation.
 
> Does the C++ language specify what the result should be? Could both results be "correct"?
 
> Any input would be appreciated.
 
Question was how did I know 'i' was still in the buffer? Because the following code returned a boolean true result:
 
if (cin.peek() == 'i')
{
cin.get(); // swallow 'i'
 
...
 
In the code above we want to confirm that 'i' is the next character in the buffer before inputting it, but don't actually want the 'i' itself.
 
I hope that answers your question to your satisfaction.
Real Troll <Real.Troll@Trolls.com>: Mar 09 06:50PM -0400

On 09/03/2018 22:32, Bob Langelaan wrote:
 
> ...
 
> In the code above we want to confirm that 'i' is the next character in the buffer before inputting it, but don't actually want the 'i' itself.
 
> I hope that answers your question to your satisfaction.
 
Thanks for posting back. I did a simple run like this:
 
#include <iostream>
 
using namespace std;
int main ()
{
int var;
cout << "Please enter an integer: ";
cin >> var;
 
cout << "You entered: " << var;
 
return 0;
}
 
 
 
It returns 12345 but I don't think it proves that i is still in the
buffer. But I take your word for it.
 
If you enter a number like: abc456
then you get 0
 
So clearly the cin parses the string and if it can't find an integer, it
returns nothing.
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Mar 09 11:17PM

On 09/03/2018 22:50, Real Troll wrote:
>  then you get 0
 
> So clearly the cin parses the string and if it can't find an integer, it
> returns nothing.
 
For fuck's sake this isn't rocket science.
 
int var;
char ch;
cin >> var;
cin >> ch;
cout << var << "," << ch << endl;
 
/Flibble
 
--
"Suppose it's all true, and you walk up to the pearly gates, and are
confronted by God," Bryne asked on his show The Meaning of Life. "What
will Stephen Fry say to him, her, or it?"
"I'd say, bone cancer in children? What's that about?" Fry replied.
"How dare you? How dare you create a world to which there is such misery
that is not our fault. It's not right, it's utterly, utterly evil."
"Why should I respect a capricious, mean-minded, stupid God who creates
a world that is so full of injustice and pain. That's what I would say."
Bob Langelaan <bobl0456@gmail.com>: Mar 09 03:21PM -0800

For fuck's sake this isn't rocket science.
 
int var;
char ch;
cin >> var;
cin >> ch;
cout << var << "," << ch << endl;
 
LOL !!! I agree :)
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: