How can i return a string? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can i return a string?

Can someone tell me how to return a string (not like "Hello world",like the name of the string) in a function? (In C++ Btw)

5th Apr 2020, 4:48 PM
Icebreaker
Icebreaker - avatar
3 Answers
+ 1
Use string type: #include <iostream> #include <string> using namespace std; string getString() { string s = "some string"; s += " result"; return s; } int main() { cout << getString() << endl; }
5th Apr 2020, 5:14 PM
andriy kan
andriy kan - avatar
+ 1
What exactly do you mean?
5th Apr 2020, 5:17 PM
Ipang
0
Do you mean the name of the string variable?
10th Nov 2020, 7:32 PM
xaralampis_
xaralampis_ - avatar