I am new to C ++ and don't understand why this code works well:
string GetString(string promt)
{
cout << promt << ": ";
string temp;
getline(cin, temp);
return temp;
}
int main()
{
string firstName = GetString("Enter your first name");
string lastName = GetString("Enter your last name");
cout<< "Your Name is: " << firstName << " " << lastName;
cin.ignore();
cin.get();
return 0;
}
String literals of type "bla" are of type const char *. At least auto i = "bla"; indicates that I have type "const char *". Why can I pass it to the GetString function because the function expects a string and not a char * constant?
source
share