>
>
>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 | |
|
|
Yahoo! Groups Links
- To visit your group on the web, go to:
http://groups.yahoo.com/group/c-prog/
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
