Answer to Question #2158 in C++ for glenn

Question #2158
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
Expert's answer
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS