gpt4 book ai didi

C++:::无法调用错误,如 Stroustrup 书中的指示

转载 作者:行者123 更新时间:2023-11-30 03:54:23 27 4
gpt4 key购买 nike

我决定自己学习 C++,我已经有了一些 Java 经验。

在 Bjarne Stroustrup 的书中他说:

Prompt the user to enter the age of the recipient and assign it to an int variable age. Have your program write "I hear you just had a birthday and You are 'age' years old." If age is 0 or less or 110 or more, call error("you're kidding! ").

在此之前的几页中,他使用错误函数如下:

double d1 = 2.3;

double d2 = d1 + 2;

if (d1 < 0)

error( "d1 is negative");

当我尝试运行我的程序时(Bjarnes 书中的练习),我得到“使用未声明的标识符‘错误’”。

我曾尝试研究我的问题,但直到现在每次都找到了解决方案,但无济于事。

如果需要,这里是我的 Main.cpp 的内容:

#include <iostream> 
using namespace std;

int main() {

cout << "Please enter the recipients name: " << endl;
string rname;
getline(cin, rname);

cout << "Ok, thank you. What is your mutual friends name: " <<endl;
string fname;
getline (cin, fname);

cout << "Ok, now what gender is you friends? 'm' for male, and 'f' for female: ";
char fsex;
cin >> fsex;

cout << "Fantastic, now how old is the recipient? " << endl;
int age;
cin >> age;
if(age >= 0 && age <= 110){
cout << "Thank you " << endl;
}
if(age <= 0 && age >= 110){
error("You're Kidding!");
}



return 0; }

最佳答案

你必须包含标题

std_lib_facilities.h

参见 the header definition

关于C++:::无法调用错误,如 Stroustrup 书中的指示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29576603/

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