![](/img/trans.png)
[英]error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'const int')|
[英]Error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' and 'std::vector<double>')
這是我的第一個StackOverflow。
當我運行代碼時,出現以下錯誤:
error: no match for 'operator>>' (operand types are 'std::istream {aka
std::basic_istream<char>}' and 'std::vector<double>')
錯誤在第9行,但我不知道為什么。
這是我的代碼:
1 #include <vector>
2 #include <iostream>
3 using namespace std;
4
5 int main() {
6
7 vector<double> numbers[10];
8 for (int i=0;i<10;i++) {
9 cin >> numbers[i];
10 }
11 }
該數字用於行,它們實際上不在代碼中。
基本上,我要創建的程序將要求我輸入10個數字。
哦,我差點忘了! 我使用Code :: Blocks版本17.12。
謝謝您的幫助。
您已經獲得了所問問題的答案,但是我建議您進一步:消除for
循環,也不要麻煩指定向量的大小:
vector<double> numbers;
copy_n(istream_iterator<double>(cin), 10, back_inserter(numbers));
哦,還有另一個細節-您可能想打破(或永遠不要形成) using namespace std;
的習慣using namespace std;
-這可能會導致問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.