Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the value of const string& in C++

Tags:

c++

I have a function that takes const string& value as argument. I am trying to get the value of this string so that I can manipulate it in the function. So I want to store the value into a string returnVal but this does not work:

string returnVal = *value

like image 683
Rini Avatar asked Jan 20 '23 11:01

Rini


2 Answers

Simply do

string returnVal = value;

Since value is not a pointer but a reference you do not need the pointer-dereferencing-operator (otherwise it would be const string *value).

like image 67
mmmmmmmm Avatar answered Jan 31 '23 13:01

mmmmmmmm


string returnVal = value;

value isn't a pointer that needs dereferencing, it's a reference and the syntax is the same as if you're dealing with a plain old value.

like image 37
Scott Langham Avatar answered Jan 31 '23 13:01

Scott Langham