this is my first StackOverflow.
When I run my code I get this error:
error: no match for 'operator>>' (operand types are 'std::istream {aka
std::basic_istream<char>}' and 'std::vector<double>')
The error is in line 9 but I don't know why.
This is my code:
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 }
This numbers are for the lines, they are not actually in the code.
Basically, what I want to create is program that will ask me for 10 numbers.
Oh, I nearly forgot! I use Code::Blocks, version 17.12.
Thanks for the help.
You've already gotten an answer to the question you asked, but I'd suggest going a step further: eliminate the for
loop and don't bother specifying the size of the vector either:
vector<double> numbers;
copy_n(istream_iterator<double>(cin), 10, back_inserter(numbers));
Oh, and one other detail--you probably want to break (or never form) the habit of using namespace std;
--it can lead to problems.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.