Consider the following snippet:
#include <iostream>
template <typename... types> void writeall(const types & ... items)
{
(std :: cout << ... << items);
}
template <typename... types> void readall(types & ... items)
{
(std :: cin >> ... >> items);
}
int main()
{
writeall(1, 2, 3, 4);
std :: cout << std :: endl;
int a, b, c, d;
readall(a, b, c, d);
}
In writeallI use fold expressions to feed std :: coutparameters into a package. Everything works fine, and I displayed 1234.
Q readall, I am doing exactly the same, expecting to read from a std :: cinpackage of parameters. However i get
error: expected ')'
(std :: cin >> ... >> items);
What am I doing wrong? One would expect that everything would work the same way, I just replaced the operator <<with the operator >>.
source
share