-
April 21st, 2004, 01:19 AM
#1
Member
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:
Code:
// 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.
-
April 21st, 2004, 02:40 AM
#2
Member
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?
-
April 21st, 2004, 03:15 AM
#3
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
-
Forum Rules
|
|