Answer to Question #2158 in C++ for glenn
I want to code a generic,reusable function named getname that will prompt the user to enter a name and store the full name in one variable
1
2011-03-29T12:33:46-0400
#include #include using namespace std;
string getname(string quest)
{
cout << quest;
char ans[256];
cin.getline (ans, 256);
return string(ans);
}
int main()
{
string a = getname("enter name: " );
cout << a << endl;
return 0;
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C++
Comments
Leave a comment