Results 1 to 4 of 4

Thread: Easy question i think

  1. #1

    Thread Starter
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    Hi, i am trying just to get classes down, and i think the class itself is ok. But whenever i try to compile this code i get errors about casting a and b to a char. They already are a char! I have no idea what is wrong.

    I know the code is useless and pointless, like i said, i am just trying to get this down.

    Code:
    #include <iostream.h>
    
    class Func {
    
    public:
    
    	void Welcome(char name);
    
    };
    
    void Func::Welcome(char name) {
    
    cout<<"Welcome to my program"<<name<<endl;
    
    }
    
    char a = "Hi";
    char b = "Hello";
    
    int main(){
    
    
    Func Start;
    Start.Welcome(a);
    Start.Welcome(b);
    
    
    return 0;
    
    
    
    }

    Thanks A LOT for any help!

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  2. #2
    Addicted Member
    Join Date
    Apr 1999
    Location
    Freeport
    Posts
    204
    Try This
    char our one byte so to place a string in them you use a array for the number a char you want plus one for the null terminator
    #include <iostream.h>
    class Func
    {
    public:
    void Welcome(char name[]);
    };
    void Func::Welcome(char name[])
    {
    cout<<"Welcome to my program "<<name<<endl;
    }
    char a[3] = "Hi";
    char b[6] = "Hello";
    int main()
    {
    Func Start;
    Start.Welcome(a);
    Start.Welcome(b);
    return 0;
    }

  3. #3

    Thread Starter
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    Thanks for the help scott, it works fine now.

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    And you can also make it simpler by using

    char *pcStr = "Hello";

    But bear in mind that this allows you to change the pointer if you really want to
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width