为什么我的程序不接受第二个输入?

Why my program isn't accepting the second input?

我不知道为什么它不接受第二个输入。帮我解决一下。

这是代码:

#include <iostream>

using namespace std;


int main()
{
    char fn,ln;
    cout<<"Enter your First Name\n"<<endl;
    cin>>fn;
    cout<<"Enter your Last Name"<<endl;
    cin>>ln;

    return 0;
}

由于char只能容纳一个字符,您可以使用std::string来存储名字。

示例:

#include <iostream>
#include <string>


int main( )
{
    std::cout << "Enter your first name\n";
    std::string firstName;
    std::getline( std::cin, firstName );

    std::cout << "Enter your last name\n";
    std::string lastName;
    std::getline( std::cin, lastName );

    std::cout << "\nHi " << firstName << ' ' << lastName << '\n';
}

样本input/output:

Enter your first name
John
Enter your last name
Connor

Hi John Connor