Return Value problems?

So I got really confused.

Differences of these Return Values?
For the first two:
return Guess;| return string();

// get a value from the player
string GetGuessAndPrintBack()
{
	cout << "Enter your guess: ";
	string Guess = "";
	getline(cin, Guess);
	
	// prints the guess back
	cout << "Your guess was " << Guess << endl;
	
	cout << endl;
	return string(); // or return Guess;
}

For the others:
| return; | return 0;| return void 0;(not sure if this one exist though)
Can any of this be used in that string function above? And when do we use them? Their differences?

Thank you guys!

Bear with me as the little voice in my head walks me through this for, hopefully, our benefit…

return Guess;
// this with return the information store in the “Guess” variable declared above your getline()

return string();
//this would return, if it works, an entire string variable however since the program is using multiple strings I am not sure it would know what information it would be referring to.

return 0;
//as I understand it, is meant to exit you out of a function and back into the “int main()”. If you already in the “int main()” it exits you out of the program as a whole… the press any key to close this window bit at the end

return; return void 0;
//not sure these work at all. My code did not run with just return…

just my thoughts, maybe someone with more experience will enlighten us further.

1 Like

Privacy & Terms