Thread: objects

  1. #1
    Registered User
    Join Date
    May 2003


    I have created an object which has a char str[]. Why cant I do any of the following
    if (obj.str =="something")
    if (obj.str != "something")
    while (obj.str != '\n')
    am I doing something wrong???? In order to do a comparison, must they both be objects???


  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    When using == you compare the pointers not the actual string. Use strcmp() to compare strings, it returns 0 if both strings match.

    In the while-loop you make a comparasion between a char and a char*, which is not valid. You probably want to pick out a single character from the string: while (obj.str[index] != '\n')

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. most efficient way to write filestream objects?
    By darsunt in forum C++ Programming
    Replies: 3
    Last Post: 01-26-2009, 05:17 PM
  2. Replies: 60
    Last Post: 12-20-2005, 11:36 PM
  3. Question about cout an stack object?
    By joenching in forum C++ Programming
    Replies: 8
    Last Post: 05-08-2005, 10:10 PM
  4. chain of objects within pop framework help needed
    By Davey in forum C++ Programming
    Replies: 0
    Last Post: 04-15-2004, 10:01 AM
  5. array of objects?
    By *~*~*~* in forum C++ Programming
    Replies: 4
    Last Post: 05-31-2003, 05:57 PM