我看了其他一些问题,我对 C++ 太陌生了,不知道它们是否适用于我的问题。
基本上当显示“名称”的输出时,如果我输入我的全名,它只会显示第二个单词。之前,它甚至什么都不吃,只是略过而已。我现在对看似简单的事情感到困惑。谢谢。
#include <iostream>
#include <string>
using namespace std;
int main()
{
double money;
string name;
int age;
// Prompt for age and receive
cout<<"How old are you? ";
cin >> age;
// Prompt for money and receive
cout<<"How much money do you have?";
cin >> money >> endl;
// Prompt for name and receive
cout<<"What's your name?\n\n"<< endl;
getline(cin, name);
// Display all information to user
cout<<"Hello, "<< name <<".";
cout << "You are " << age << " years old";
cout<< " and have $" << money << ".\n";
system("PAUSE");
return 0;
}