+ 3

How do I return a string from a function? (C++)

Hi! I want to have a string as a return of my function, but I don't know if it is actually possible. If yes, how can I do it? 😊

21st Mar 2018, 6:30 PM
Lena
7 Answers
22nd Mar 2018, 3:52 AM
Tanay
Tanay - avatar
+ 6
char* func(char* s) { Char* string = s; return string; } // there is no string type in C
21st Mar 2018, 9:45 PM
H. Ahmadian
H. Ahmadian - avatar
+ 3
string function(){ string s = "How to"; return s; }
21st Mar 2018, 6:34 PM
Alex
Alex - avatar
+ 3
Sure. string test() { return "test"; } int main() { cout << test(); }
21st Mar 2018, 6:36 PM
Toni Isotalo
Toni Isotalo - avatar
+ 2
c != c++
21st Mar 2018, 11:37 PM
Alex
Alex - avatar
+ 1
Oh okay it's just this, thank you! 👌 😊
21st Mar 2018, 6:39 PM
Lena
+ 1
That’s what I though also but it worked on sololearn so
21st Mar 2018, 9:52 PM
Toni Isotalo
Toni Isotalo - avatar