Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #15408 > unrolled thread

Some Basics - strings and Conversions

Started bymrc2323@cox.net (Mike Copeland)
First post2012-04-16 16:07 -0700
Last post2012-04-17 13:50 +0000
Articles 11 — 6 participants

Back to article view | Back to comp.lang.c++


Contents

  Some Basics - strings and Conversions mrc2323@cox.net (Mike Copeland) - 2012-04-16 16:07 -0700
    Re: Some Basics - strings and Conversions red floyd <no.spam.here@its.invalid> - 2012-04-16 16:50 -0700
      Re: Some Basics - strings and Conversions mrc2323@cox.net (Mike Copeland) - 2012-04-17 14:59 -0700
        Re: Some Basics - strings and Conversions Ian Collins <ian-news@hotmail.com> - 2012-04-18 10:43 +1200
          Re: Some Basics - strings and Conversions mrc2323@cox.net (Mike Copeland) - 2012-04-17 20:43 -0700
            "ThePirateBay.SE" has a cracked copy of Visual Studio 2010.  @Jeff-Relf.Me - 2012-04-17 20:55 -0700
            Re: Some Basics - strings and Conversions Miles Bader <miles@gnu.org> - 2012-04-18 13:27 +0900
              Re: Some Basics - strings and Conversions Miles Bader <miles@gnu.org> - 2012-04-18 13:31 +0900
              Re: Some Basics - strings and Conversions drew@furrfu.invalid (Drew Lawson) - 2012-04-18 17:33 +0000
    Re: Some Basics - strings and Conversions Ian Collins <ian-news@hotmail.com> - 2012-04-17 15:49 +1200
      Re: Some Basics - strings and Conversions drew@furrfu.invalid (Drew Lawson) - 2012-04-17 13:50 +0000

#15408 — Some Basics - strings and Conversions

Frommrc2323@cox.net (Mike Copeland)
Date2012-04-16 16:07 -0700
SubjectSome Basics - strings and Conversions
Message-ID<MPG.29f6542782c9bee9896fe@news.eternal-september.org>
   In the following code, even though the program executes, the 2nd 
prompt fails to process data.  The 1st prompt requires 2 returns (why is 
that?), but the 2nd doesn't: it prompts, waits for data, and goes on to 
the last "cout" with no value in "quantity".
   I know this is basic C++ stuff, but I'm trying to convert my massive 
C code applications (particularly using C strings) to something more 
acceptable here: basic::strings and directed I/o and conversions.  Thus, 
I'm learning this stuff for the first time... 8<{{  TIA

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main ()
{
  string mystr;
  float  price    = 0;
  int    quantity = 0;

  cout << "Enter Price and Description: ";      // numeric & text
  getline (cin, mystr);
  stringstream(mystr) >> price; // parse only the numeric portion
  cout << "Enter quantity: ";
  getline (cin, mystr);
  stringstream(mystr) >> quantity;
  cout << "Total price: " << price*quantity << endl;
  return 0;
}

[toc] | [next] | [standalone]


#15409

Fromred floyd <no.spam.here@its.invalid>
Date2012-04-16 16:50 -0700
Message-ID<jmib8t$uvl$1@dont-email.me>
In reply to#15408
On 4/16/2012 4:07 PM, Mike Copeland wrote:
>     In the following code, even though the program executes, the 2nd
> prompt fails to process data.  The 1st prompt requires 2 returns (why is
> that?), but the 2nd doesn't: it prompts, waits for data, and goes on to
> the last "cout" with no value in "quantity".
[redacted]

What platform and compiler are you using?  It looks OK source-wise,
and it works for me, compiling with 0 warnings, g++ 4.5.3, Cygwin.

>
> #include<iostream>
> #include<string>
> #include<sstream>
> using namespace std;
>
> int main ()
> {
>    string mystr;
>    float  price    = 0;
>    int    quantity = 0;
>
>    cout<<  "Enter Price and Description: ";      // numeric&  text
>    getline (cin, mystr);
>    stringstream(mystr)>>  price; // parse only the numeric portion
>    cout<<  "Enter quantity: ";
>    getline (cin, mystr);
>    stringstream(mystr)>>  quantity;
>    cout<<  "Total price: "<<  price*quantity<<  endl;
>    return 0;
> }

[toc] | [prev] | [next] | [standalone]


#15436

Frommrc2323@cox.net (Mike Copeland)
Date2012-04-17 14:59 -0700
Message-ID<MPG.29f795ae2a8da7709896ff@news.eternal-september.org>
In reply to#15409
In article <jmib8t$uvl$1@dont-email.me>, no.spam.here@its.invalid 
says...
> >     In the following code, even though the program executes, the 2nd
> > prompt fails to process data.  The 1st prompt requires 2 returns (why is
> > that?), but the 2nd doesn't: it prompts, waits for data, and goes on to
> > the last "cout" with no value in "quantity".
> [redacted]
> 
> What platform and compiler are you using?  It looks OK source-wise,
> and it works for me, compiling with 0 warnings, g++ 4.5.3, Cygwin.
> 
   VS6.0, Windows XP SP3
   No errors, just bizarre inconsistent behavior... 8<{{

[toc] | [prev] | [next] | [standalone]


#15437

FromIan Collins <ian-news@hotmail.com>
Date2012-04-18 10:43 +1200
Message-ID<9v6a0hFqiiU2@mid.individual.net>
In reply to#15436
On 04/18/12 09:59 AM, Mike Copeland wrote:
> In article<jmib8t$uvl$1@dont-email.me>, no.spam.here@its.invalid
> says...
>>>      In the following code, even though the program executes, the 2nd
>>> prompt fails to process data.  The 1st prompt requires 2 returns (why is
>>> that?), but the 2nd doesn't: it prompts, waits for data, and goes on to
>>> the last "cout" with no value in "quantity".
>> [redacted]
>>
>> What platform and compiler are you using?  It looks OK source-wise,
>> and it works for me, compiling with 0 warnings, g++ 4.5.3, Cygwin.
>>
>     VS6.0, Windows XP SP3

Nobody in their right mind uses VS6 these days!

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#15444

Frommrc2323@cox.net (Mike Copeland)
Date2012-04-17 20:43 -0700
Message-ID<MPG.29f7e645defda46f989700@news.eternal-september.org>
In reply to#15437
In article <9v6a0hFqiiU2@mid.individual.net>, ian-news@hotmail.com 
says...
> >>>      In the following code, even though the program executes, the 2nd
> >>> prompt fails to process data.  The 1st prompt requires 2 returns (why is
> >>> that?), but the 2nd doesn't: it prompts, waits for data, and goes on to
> >>> the last "cout" with no value in "quantity".
> >> [redacted]
> >>
> >> What platform and compiler are you using?  It looks OK source-wise,
> >> and it works for me, compiling with 0 warnings, g++ 4.5.3, Cygwin.
> >>
> >     VS6.0, Windows XP SP3
> 
> Nobody in their right mind uses VS6 these days!
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   Yes, I get that a lot.  8<{{
   If I could switch to one of the free compilers, I would do so.  
However, with over 1,000,000 lines of code with dependencies on STL and 
other things that don't seem to be in the free versions, I can't.  And 
obviously, I can't afford to purchase a paid version... <sigh>

[toc] | [prev] | [next] | [standalone]


#15445 — "ThePirateBay.SE" has a cracked copy of Visual Studio 2010. 

From@Jeff-Relf.Me
Date2012-04-17 20:55 -0700
Subject"ThePirateBay.SE" has a cracked copy of Visual Studio 2010. 
Message-ID<Jeff-Relf.Me@2012_Apr.17^8.55^PM>
In reply to#15444
<PRE>
"ThePirateBay.SE" has a cracked copy of Visual Studio 2010.  See:

  http://groups.google.com/group/news.software.readers/msg/b56104664695f711
  news:Jeff-Relf.Me@2012_Feb.15^0.04.pm

[toc] | [prev] | [next] | [standalone]


#15446

FromMiles Bader <miles@gnu.org>
Date2012-04-18 13:27 +0900
Message-ID<874nsh1x6t.fsf@catnip.gol.com>
In reply to#15444
mrc2323@cox.net (Mike Copeland) writes:
>> Nobody in their right mind uses VS6 these days!
>    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    Yes, I get that a lot.  8<{{
>    If I could switch to one of the free compilers, I would do so.  
> However, with over 1,000,000 lines of code with dependencies on STL and 
> other things that don't seem to be in the free versions, I can't.

Wait, there are free C++ compilers without an STL implementation?!

-miles

-- 
Alliance, n. In international politics, the union of two thieves who have
their hands so deeply inserted in each other's pockets that they cannot
separately plunder a third.

[toc] | [prev] | [next] | [standalone]


#15447

FromMiles Bader <miles@gnu.org>
Date2012-04-18 13:31 +0900
Message-ID<87vckxzmnm.fsf@catnip.gol.com>
In reply to#15446
Miles Bader <miles@gnu.org> writes:
> mrc2323@cox.net (Mike Copeland) writes:
>>> Nobody in their right mind uses VS6 these days!
>>    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>    Yes, I get that a lot.  8<{{
>>    If I could switch to one of the free compilers, I would do so.  
>> However, with over 1,000,000 lines of code with dependencies on STL and 
>> other things that don't seem to be in the free versions, I can't.
>
> Wait, there are free C++ compilers without an STL implementation?!

BTW, I suspect a bigger problem is that you've probably got 1,000,000
lines of code with dependencies on the wacky non-standard behavior of
VS6...

-miles

-- 
Happiness, n. An agreeable sensation arising from contemplating the misery of
another.

[toc] | [prev] | [next] | [standalone]


#15456

Fromdrew@furrfu.invalid (Drew Lawson)
Date2012-04-18 17:33 +0000
Message-ID<jmmtt9$2bh7$1@raid.furrfu.com>
In reply to#15446
In article <874nsh1x6t.fsf@catnip.gol.com>
	Miles Bader <miles@gnu.org> writes:
>mrc2323@cox.net (Mike Copeland) writes:
>>> Nobody in their right mind uses VS6 these days!
>>    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>    Yes, I get that a lot.  8<{{
>>    If I could switch to one of the free compilers, I would do so.  
>> However, with over 1,000,000 lines of code with dependencies on STL and 
>> other things that don't seem to be in the free versions, I can't.
>
>Wait, there are free C++ compilers without an STL implementation?!

I suspect he means MFC.
That's the main thing Microsoft leaves out of their free versions.
And, of course, no one else implements that.

-- 
Drew Lawson            |  "But the senator, while insisting he was not
                       |   intoxicated, could not explain his nudity."

[toc] | [prev] | [next] | [standalone]


#15413

FromIan Collins <ian-news@hotmail.com>
Date2012-04-17 15:49 +1200
Message-ID<9v47iaFoqtU1@mid.individual.net>
In reply to#15408
On 04/17/12 11:07 AM, Mike Copeland wrote:
>     In the following code, even though the program executes, the 2nd
> prompt fails to process data.  The 1st prompt requires 2 returns (why is
> that?), but the 2nd doesn't: it prompts, waits for data, and goes on to
> the last "cout" with no value in "quantity".

It shouldn't.  What platform are you using?

<snip>

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#15428

Fromdrew@furrfu.invalid (Drew Lawson)
Date2012-04-17 13:50 +0000
Message-ID<jmjseh$okh$1@raid.furrfu.com>
In reply to#15413
In article <9v47iaFoqtU1@mid.individual.net>
	Ian Collins <ian-news@hotmail.com> writes:
>On 04/17/12 11:07 AM, Mike Copeland wrote:
>>     In the following code, even though the program executes, the 2nd
>> prompt fails to process data.  The 1st prompt requires 2 returns (why is
>> that?), but the 2nd doesn't: it prompts, waits for data, and goes on to
>> the last "cout" with no value in "quantity".
>
>It shouldn't.  What platform are you using?

The description of behavior sounds like things are working, but he
doesn't see the second prompt until after pretting return the second
time.

I forget the rules, but see that the prompts are not newline terminated.
Does he need to explicitly flush cout, or does reading cin trigger that?


-- 
                        | Stories of tortures used by debauchers
 Drew Lawson            | lurid, licentious and vile
                        | make me smile

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web