Archived

This topic is now archived and is closed to further replies.

cin.ignore()

This topic is 4951 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

cin.ignore( 256, ''\n'' ) what do the numbers mean in the parameters? Ignore the first 256 characters? Or is 256 representing the char/symbol values?

Share this post


Link to post
Share on other sites
one more question...

can arrays be deleted without being a class private member variable?

for example, can i do this:

char sName[ 50 ];
....
...
...
...
delete [ ] sName; // i think thats how you delete

[edited by - TheOne1 on May 28, 2004 12:04:57 AM]

Share this post


Link to post
Share on other sites
Yes. If an array was created with new then it must be deleted with delete.


char *some_stuff = new char[300];

//use some_stuff


//Free the memory that some_stuff points to

delete [] some_stuff;


NB: brackets are used after delete only when you use brackets when you use new. Compare with the above

   
char *a_char = new char;

//use a_char


//Free the memory that a_char points to

delete a_char;


You do NOT delete arrays that were not created with new. In your example sName is created on the stack and is automatically freed when it goes out of scope.


Thanks Salsa!Colin Jeanne | Invader's Realm
"I forgot I had the Scroll Lock key until a few weeks ago when some asshole program used it. It even used it right" - Conner McCloud

[edited by - Invader X on May 28, 2004 12:16:38 AM]

Share this post


Link to post
Share on other sites