向量< int>v(istream_iterator< int(cin),istream_iterator< int>()); [英] vector<int> v(istream_iterator<int>(cin), istream_iterator<int>());
本文介绍了向量< int>v(istream_iterator< int(cin),istream_iterator< int>());的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;
int main()
{
vector<int> v(istream_iterator<int>(cin), istream_iterator<int>()); //Compilation error?!
copy(v.begin(), v.end(), ostream_iterator<int>(cout, "\n"));
return 0;
}
为什么该行出错?我知道编译器将"v"作为函数!很棒...
Why that line goes error? I know the compiler thouht 'v' as a function! Amazing...
推荐答案
此问题被称为C ++的最烦人的问题解析.
This problem is known as C++'s most vexing parse.
尝试将第一行更改为以下内容(注意多余的括号):
Try changing the first line to the following (note the extra parentheses):
vector<int> v((istream_iterator<int>(cin)), istream_iterator<int>());
这篇关于向量< int>v(istream_iterator< int(cin),istream_iterator< int>());的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文