+ 2

can i send a string as parameter?

yesterday i try to send a string to a function in c++. But i dont know how can i send that. if anyone can ,try it. send a string as "sujith" and change it to "john" in a function

17th Jun 2018, 8:06 AM
sujith
sujith - avatar
5 Respostas
+ 11
void change(std::string& str) { str = "john"; } int main() { std::string test = "Sujith"; change(test); }
17th Jun 2018, 9:03 AM
Hatsy Rei
Hatsy Rei - avatar
+ 12
By reference or value?
17th Jun 2018, 8:09 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 3
by reference may be good
17th Jun 2018, 8:10 AM
sujith
sujith - avatar
+ 2
in any way
17th Jun 2018, 8:10 AM
sujith
sujith - avatar
0
thank you for your best answer. can we change the program into return a string?
17th Jun 2018, 9:37 AM
sujith
sujith - avatar