题目链接 (https://www.acwing.com/problem/content/610/)
我遇到了cin后加 endl; 报错问题。
错误的代码:
#include <iostream>
using namespace std;
int main(){
int A , B , C , D;
cin >> A >> B >> C >> D >> endl ;
cout<< "DIFERENCA = " << A * B - C * D << endl;
return 0;
}
编译器报了什么错误?
a.cpp: In function 'int main()':
a.cpp:8:29: error: no match for 'operator>>' (operand types are 'std::basic_istream<char>::__istream_type' {aka 'std::basic_istream<char>'} and '<unresolved overloaded function type>')
8 | cin >> A >> B >> C >> D >> endl ;
百度后得到解答:
cin代表标准输入设备,使用提取运算符 “>>” 从设备键盘取得数据,送到输入流对象cin中,然后送到内存。使用cin可以获得多个从键盘的输入值,其具体使用格式如下:
cin >> 表达式1 >>表达式2 … >> 表达式n;
这个是c++中做的语法规定。
endl 并不是一个变量,所以不能 cin
!谢谢