Tell if a string is empty?

This is a discussion on Tell if a string is empty? within the C++ Programming forums, part of the General Programming Boards category; Is there any way to tell if a string is empty... such as: char name[10]; if (name=="EMPTY??") { do this ...

  1. #1
    Registered User dizz's Avatar
    Join Date
    Nov 2002
    Posts
    41

    Tell if a string is empty?

    Is there any way to tell if a string is empty... such as:

    char name[10];

    if (name=="EMPTY??")
    {
    do this
    }

    Any help would be great!!

  2. #2
    Registered User Pioneer's Avatar
    Join Date
    Dec 2002
    Posts
    59
    Code:
    if (name[0]==0){
        do this
    }

  3. #3
    Registered User dizz's Avatar
    Join Date
    Nov 2002
    Posts
    41
    thanx
    but i figured it out with strcmp
    hahaha sometimes i feel so stupid LMAO!

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    How about using the string class?

    Code:
    #include <string>
    
    using std::string;
    
    string name;
    
    if(name.empty()) {
        // do stuff
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 07:02 AM
  2. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 02:02 AM
  3. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 01:56 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM

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