gpt4 book ai didi

c++ - 我怎样才能阻止链跳线?

转载 作者:行者123 更新时间:2023-12-05 04:35:06 25 4
gpt4 key购买 nike

<分区>

我试图制作一个程序,要求用户提供输入并给出带有已回答问题的输出。一切看起来都很好,除了 cin 跳过了我最后一个关于学校的问题。

这是原始代码:

//this program fills my data in profile

#include <iostream>
#include <string>

using namespace std;

int main () {

int age, exp_years;
char desired_grade;
string school_name, name;
const int year_grad = 4;
bool is_student;

cout << "You will need to enter your data for portfolio card" << endl;
cout << "Enter your last name" << endl;
cin >> name;
cout << "Enter your age" << endl;
cin >> age;
cout << "Enter your years of work experience" << "\n";
cin >> exp_years;
cout << "Is it true or false that you are a student (put 'true' or 'false')" << endl;
cin >> is_student;
cout << "Great! What school are you in (if you are not a student put desirable school)?" << endl;
cin >> school_name;

/* trying to make a function below */

cout << "Awesome, here is your info" << endl << "Your last name is "<< name << endl <<"You are "<<age << " years old." << endl << exp_years << " years of work experience" << endl;
if ( is_student == 1)
{
cout << school_name << " is lucky to have you!\n";
return 0;
} else {
cout << "Btw I am sure that " << school_name << " would be happy to have you as their student anytime\n";
return 0;
}

return 0;
}

我读了一些文章,他们说 getline() 可以提供帮助,所以我尝试用:

cout << "Is it true or false that you are a student (put 'true' or 'false')" << endl;
getline(cin, is_student);
cout << "Great! What school are you in (if you are not a student put desirable school)?" << endl;
getline(cin, school_name);

然而,它给了我一个错误:

error: no matching function for call to 'getline'

我错过了什么?

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