Question: #include #include using namespace std; int main ( ) { string userName; string userAddress; cout < < ; getline ( cin , userName

#include
#include
using namespace std;
int main(){
string userName;
string userAddress;
cout <<"";
getline(cin, userName);
cout <<"";
getline(cin, userAddress);
cout << userName << endl;
cout << userAddress << endl;
return 0;
}
zybook tells me its wrong cin is used to read the string variable userName from input, since the name is assumed to be a single word.
Then, getline() is used to read the string variable userAddress from input, since the address is assumed to contain multiple words.
Ex: For input Rob 567 Second Avenue, the cin statement gets characters until the next whitespace, so "Rob" is read, stopping at the space after Rob. Then, the getline() statement gets all the remaining text on the input line, so "567 Second Avenue" is read, including the leading space.
what am i doing wrong?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!