Re: basic char and int array loading
From: zentara (zentara_at_highstream.net)
Date: 12/13/04
- Next message: jcoffin_at_taeus.com: "Re: Beginner Syntax Question"
- Previous message: Alwyn: "Re: STL Usage [Re: My brains have gone dry and flakey ...]"
- In reply to: Ulrich Eckhardt: "Re: basic char and int array loading"
- Next in thread: B. v Ingen Schenau: "Re: basic char and int array loading"
- Reply: B. v Ingen Schenau: "Re: basic char and int array loading"
- Reply: Ulrich Eckhardt: "Re: basic char and int array loading"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 13 Dec 2004 07:21:16 -0500
On Sun, 12 Dec 2004 01:21:03 +0100, Ulrich Eckhardt <doomster@knuut.de>
wrote:
>
>This calls operator>>( istream&, int&). If you enter e.g. 'e', the operator
>will try to convert that input to a number and fail. The input remains in
>the stream's buffer and all subsequent input operations will fail, until
>you clear() the stream.
>
>If you want the byte-value of an entered char, you need to read it as such:
> char tmp;
> cin>>tmp;
> // convert to unsigned char first to suppress sign promotion
> unsigned value = static_cast<unsigned char>(tmp);
>
>BTW:
>- you can do more than 'i++' in the for statement, e.g. 'i++, j++'
>- in that loop, i always has the same value as j
>- you can declare and initialise vars in a for statement:
> for(int i(0); i!=5; ++i) { ... }
>- a char has always size 1, not only on your system. An int doesn't always
>have size 4 though, that's just your system.
Thanks for the insights. The explanation of the failed data remaining
in the stream's buffer now makes things understandable.
Comparing this to Perl, I don't worry about whether a piece of data
is string or numeric. So I was wondering, is there a generally used
way in C++, to load an array with a combination of strings and numerics,
so that it is all handled gracefully, or do I need to do all the testing
and clearing myself?
Do you just pull everything in as strings, and worry about converting
string to int or double later?
-- I'm not really a human, but I play one on earth. http://zentara.net/japh.html
- Next message: jcoffin_at_taeus.com: "Re: Beginner Syntax Question"
- Previous message: Alwyn: "Re: STL Usage [Re: My brains have gone dry and flakey ...]"
- In reply to: Ulrich Eckhardt: "Re: basic char and int array loading"
- Next in thread: B. v Ingen Schenau: "Re: basic char and int array loading"
- Reply: B. v Ingen Schenau: "Re: basic char and int array loading"
- Reply: Ulrich Eckhardt: "Re: basic char and int array loading"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|