Your function
temp
accepts a string into a temporary variable. Then, when it returns to
main
the temporary variable
s
goes out of scope and is destroyed. You code should be:
string temp()
{
string s;
getline(cin,s); return s;
}
int main()
{
string s;
s = temp(); return 0;
}