could use a little help

This is a discussion on could use a little help within the C++ Programming forums, part of the General Programming Boards category; Just wondering if someone could help me with a problem i'm having, i have a class with member functions and ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    57

    could use a little help

    Just wondering if someone could help me with a problem i'm having, i have a class with member functions and a few variables. The program is supposed to do some calculations and then output something specific to the screen depending on what the input was. heres the problem, the only way i can output is by typing the following command in main

    cout << "bluh bluh bluh is" << function() << endl;

    i need to output an entire word but i cant figure out how to return a whole string instead of just a character, i believe it has something to do with pointers if that helps. i have tried to work this out on my own for hours and just cant seem to get anywhere. thanks in advance.

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    You can char arrays wich hold entire words, But for beginners (
    are you?) i recommend using the string class, Can't find a
    tutorial right now so:

    Code:
    #include <string>
    
    using namespace std;
    
    string afunction()
    {
    return "hohoho";
    }
    
    int main()
    {
    
    cout << afunction() << endl;
    
    return 0;
    }

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    57
    thanks for the response, i tried that and still got an error message. it says something about no operator defined. i think its basically saying that I cant have a function of type string to the right of <<

    some other things i didnt mention before are that the function i am using is a friend function of a class. it takes two arguments of the type of the class. example:
    class example
    ......

    main()
    example ex1, ex2
    cout <<"bluhhhhhhhh is" << function(ex1,ex2)

    my questions are......can i use a string type for a function if its a
    friend function and why might i still be getting that error message

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Could you post your entire code? I can't resolve an error with
    no code...

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    57
    i emailed it to you if thats alright

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Problem is simple, Use <iostream> instead of <iostream.h>,
    <iostream.h> is an old version.

  7. #7
    Registered User
    Join Date
    Feb 2003
    Posts
    57
    awsome.....works fine now. thanks for your help, it may have been simple but there was no way i was going to find that. that string type will def be coming in handy now.

Popular pages Recent additions subscribe to a feed

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