cant figure it out

This is a discussion on cant figure it out within the C++ Programming forums, part of the General Programming Boards category; yes, but there's not much actually enforcing it so be very very afraid. As said, use the C++ string type ...

  1. #16
    chococoder
    Join Date
    Nov 2004
    Posts
    515
    yes, but there's not much actually enforcing it so be very very afraid.

    As said, use the C++ string type instead. It's much nicer and less prone to giving you all kinds of nasty runtime errors.

  2. #17
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,799
    If you decide to use the character array you would not be able to simply compare what the user typed with the string literal "David", you'd have to use the strcmp function.

    Code:
    char password[20];
    
    cout << "Password: ";
    cin >> password;
    if( password == "David" ) // Can't do this!
    Code:
    char password[20];
    
    cout << "Password: ";
    cin >> password;
    if( strcmp(password,"David") == 0 ) // Can do this!
    You should include the <cstring> header if you want to do that.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

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

Similar Threads

  1. Figure out how method was called?
    By jcafaro10 in forum C++ Programming
    Replies: 2
    Last Post: 02-07-2009, 09:43 AM
  2. 3 dimensional figure volume
    By thekautz in forum C++ Programming
    Replies: 2
    Last Post: 01-20-2009, 04:22 PM
  3. trying to figure out someone's code for a plugin
    By paulpars in forum C++ Programming
    Replies: 4
    Last Post: 07-20-2006, 10:57 AM
  4. newb to C, cant figure something out.
    By Phate4219 in forum C Programming
    Replies: 16
    Last Post: 03-06-2006, 12:47 AM
  5. ahh i can't figure out this loop
    By blindleaf in forum C Programming
    Replies: 1
    Last Post: 03-18-2003, 08:42 AM

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