gpt4 book ai didi

c++ - 为什么跳过 std::getline()?

转载 作者:太空狗 更新时间:2023-10-29 20:25:04 26 4
gpt4 key购买 nike

<分区>

我有这个 C++ 简单程序;

#include <iostream>
using std::endl;
using std::cout;
using std::cin;
using std::getline;

#include <string>
using std::string;


struct Repository
{
string name;
string path;
string type;
string command;
};


int main()
{
Repository rp;

cout << "\nEnter repo name: ";
cin >> rp.name;

cout << "Enter repo path: ";
cin >> rp.path;

cout << "Enter repo type: ";
cin >> rp.type;

cout << "Enter repo command: ";
getline(cin, rp.command);

cout << "\nRepository information: " << endl;
cout << rp.name << "\n" << rp.path << "\n" << rp.type << "\n" << rp.command << endl;

return 0;
}

当执行到 getline(cin, rp.command) 时,程序只打印“Enter repo command:”并跳过 getline(cin, rp.command) 行,这样用户就没有时间响应。可能的问题是什么?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com