C++显示error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'const long long int')
时间: 2024-06-05 14:07:36 浏览: 22
这个错误提示表明在代码中,你正在尝试使用输入运算符(>>)来读取一个类型为 long long int 的常量,但是编译器无法找到一个适合的输入运算符来执行这个操作。可能是因为你没有为 long long int 类型重载输入运算符。可以参考 C++ 标准库中的输入输出流(iostream)库来编写自定义的输入运算符,或者使用其他方法来读取这个 long long int 常量。
相关问题
45 5 D:\c++编程\main299.cpp [Error] no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' and 'Account')
这个错误是由于你在使用`operator>>`时,没有正确地定义`Account`类的输入运算符。你需要在`Account`类中定义一个输入运算符,以便可以从`std::istream`对象中读取数据并将其存储到`Account`对象中。例如,你可以这样定义输入运算符:
```cpp
std::istream& operator>>(std::istream& is, Account& acc) {
is >> acc.balance >> acc.id >> acc.name;
return is;
}
```
在这个例子中,假设`Account`类有`balance`、`id`和`name`三个数据成员。这个输入运算符将从输入流中依次读取这三个数据,并将它们存储到`acc`对象中。你可以根据你的具体情况进行修改。
D:\C语言\新建文件夹\homework\7.1.cpp|95|error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'ElemType [4]')|
这个错误是因为你尝试使用输入运算符`>>`来直接输入一个数组,而输入运算符`>>`是无法直接输入数组的。
如果你想输入一个数组,可以使用循环结构,逐个输入数组中的元素。以下是一个示例代码:
```c++
#include <iostream>
using namespace std;
const int MAXSIZE = 4;
int main() {
int a[MAXSIZE];
cout << "请输入" << MAXSIZE << "个整数:" << endl;
for(int i=0; i<MAXSIZE; i++) {
cin >> a[i];
}
cout << "输入的整数为:";
for(int i=0; i<MAXSIZE; i++) {
cout << a[i] << " ";
}
cout << endl;
return 0;
}
```
在上面的代码中,我们首先定义了一个长度为`MAXSIZE`的整型数组`a`,然后使用循环结构逐个输入数组中的元素,并输出输入的整数。需要注意的是,循环的次数需要等于数组的长度。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)