我想输入我的函数的值,它是这样的:运行函数的std :: istream的
int funkcija(std::istream & in) {
int value(0);
in >> value;
if(not in) throw std::exception();
if(value%2 == 0) {
return (value/2);
}
else return (value*3)+1;
}
当我尝试运行它:
int i(0);
std::cout << "Input a number: ";
std::cin >> i;
funkcija(i);
我得到一个错误: .. \ working.cpp:17:14:错误:类型'std :: istream & {aka std :: basic_istream &}'的引用无效初始化''int' .. \ working。 cpp:7:5:错误:在传递'int funkcija(st d :: istream &)'
这是什么意思,以及如何解决它?谢谢!
不应该呼叫是'I = funkcija(CIN);'??? –