Thread: trouble with checking a string..

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #19
    Registered User
    Join Date
    May 2003
    Posts
    82
    Code:
    #include<iostream>
    #include<cstring>
    using namespace std;
    
    int main()
    {
        string old_name;
        // presumably assign old_name somewhere in here.
           
        if(!old_name.empty()) // easy to read conditional.
        {
            char* new_name = new char[4];
            strncpy(new_name, old_name.c_str(), 4);
            // do what you got to do with a non-empty c-string
            // All the messy c-string work is isolated here.
            
            cout << new_name << endl;
        }
        else
        {
            cout << "empty" << endl;
        }
        
        cin.get();
        return 0;
    }
    Last edited by AH_Tze; 02-10-2005 at 12:28 AM. Reason: forgot a few lines

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  5. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM