curiosity about cin.get() and cin.getline()

This is a discussion on curiosity about cin.get() and cin.getline() within the C++ Programming forums, part of the General Programming Boards category; Code: char buffer[100] = {0}; It fills the array with zeros....

  1. #16
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Code:
    char buffer[100] = {0};
    It fills the array with zeros.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #17
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    oh kool what if i wanted to declare each array with a different value or like do 20 with one and the rest with another how might i do that?
    hooch

  3. #18
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    In that case, I would use a loop:
    Code:
    char buffer[100];
    int i;
    
    for (i=0;i<100;i++)
    {
         if (i<60) buffer[i]=20;
         else buffer[i]=30;
    }
    That'll fill up the first sixty elements with 20, and the last 40 elements with 30.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #19
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    ah the info is much appreciated shoulda guessed it was a loop lol
    hooch

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cin.getline help
    By Cool Dude 2k in forum C Programming
    Replies: 2
    Last Post: 07-27-2005, 07:55 PM
  2. cin.getline and msgrcv
    By osal in forum C++ Programming
    Replies: 2
    Last Post: 03-17-2005, 12:01 PM
  3. cin.getline()
    By Ifurita. in forum C++ Programming
    Replies: 4
    Last Post: 05-29-2003, 02:14 PM
  4. problem with cin.getline()
    By Waldo2k2 in forum C++ Programming
    Replies: 8
    Last Post: 05-28-2002, 06:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21