Results 1 to 3 of 3

Thread: C++ functions (returning strings)

  1. #1

    Question C++ functions (returning strings)

    This is in C/C++:
    Ok, I get how returning numbers, characters, bool, but how would I return a string. Such as:
    // header files here
    char foo();
    int main()
         return 0;
    char foo()
         bar[7] = "foobar";
         return  bar;
    How do I get a function to return a string?
    E, the modern pi.

  2. #2
    you can't really return a string... what you can do is send an array of characters by pointers or a string (from string.h) by referance.

    Now, i have read that you can setup a function like

    string goodbye()
    return( "thank you for using this program");

    but i've had mixed results

    You should also consult your compiler's help manual to see if this kind of stuff will work.

    have fun
    You are so bored that you are reading my signature?

  3. #3
    Senior Member
    Join Date
    Dec 2003
    Pacific Northwest
    Good Evening,

    yep, but passing strings by ref is better pop this in it:

    void myfunc(string &s);

    buts if you really want to:

    string myfunc(int, int);

    good luck

Posting Permissions

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