At 03:37 PM 12/17/2004 -0000, darkshadow_x21 writeth:
>
>
>Hi i am a high school student taking a programming course and i am
>stuck on the structure problem i am currently on. When ever io add a
>whitespace to the input field the value after the space gets taken
>for the value of the next variable. (by the way i already used
>cin.get)plz help. i am really stuck so any advice would help.
>here is the problem:
>
>#include <iostream.h>
>struct address_info
>{
> char name_1st[20];
> char name_mid[2];
> char name_last[20];
> char home_address[30];
> char city[20];
> char state[2];
> char zip_code[10];
> char country[20];
> char phone[20];
> char email[30];
>};
>
>void main ()
>{
> address_info person1;
>
> cout<<"Enter First Name:"<<endl;
> cin.get(person1.name_1st,20);

If you are going to use C++, you might as well also use STL.  Instead of
static buffers and risk an overflow scenario that could be exploited, you
should be using the STL string classes:

struct address_info
{
  string name_1st;
...
};

Then:

  cin.getline(person1.name_1st);

The getline() function is overloaded to accept a STL string.  The string
class manages itself, which is good news for you because you only have to
worry about reading in the data and processing it - not whether there is an
exploitable bug in your code because you might accidentally type "30"
instead of "20" and not notice.


Thomas J. Hruska
[EMAIL PROTECTED]

Shining Light Productions
Home of the Nuclear Vision scripting language and ProtoNova web server.
http://www.slproweb.com/



To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.


Yahoo! Groups Sponsor
ADVERTISEMENT
click here
Web Bug from http://us.adserver.yahoo.com/l?M=294855.5468653.6549235.3001176/D=groups/S=:HM/A=2455397/rand=150935296


Yahoo! Groups Links

Reply via email to