C++ 我得到一个关于std::istream和intx的错误 #包括“stdafx.h” #包括 int sqr(int x)//sqr表示x的平方 { 返回x*x; } int _tmain(int argc,_TCHAR*argv[] { 标准:cout>sqr(x); std::cout

C++ 我得到一个关于std::istream和intx的错误 #包括“stdafx.h” #包括 int sqr(int x)//sqr表示x的平方 { 返回x*x; } int _tmain(int argc,_TCHAR*argv[] { 标准:cout>sqr(x); std::cout,c++,C++,只能读入变量: #include "stdafx.h" #include <iostream> int sqr ( int x ) //sqr means square of x { return x * x ; } int _tmain(int argc, _TCHAR* argv[]) { std::cout << "enter ur number"; int x ; std::cin >> sqr (x)

只能读入变量:

#include "stdafx.h"
#include <iostream> 

int sqr ( int x ) //sqr means square of x 
{

    return x * x ;
}

int _tmain(int argc, _TCHAR* argv[])
{

    std::cout << "enter ur number";
    int x ;
    std::cin >>   sqr (x) ;
    std::cout << "square of ur number is : " << sqr  ;
        return 0 ;
}
但您可以输出任何(适当类型的)表达式的值:

std::cin >> x;

std::难道您不能将“仅读入变量”:
std::cin>>id(x)
同样适用于合适的函数
id
…因此,您能建议我在哪里更改代码吗…很抱歉,我是一个noob@KerrekSB:事实上,您可以读入任何表示适当类型变量的左值表达式。我将继续使用缩写版本来回答这个问题。@DeepakDahiya:我已经读入了。更改<代码>>>sqr(x)
>>x
,并且
thnxx-bro它工作了…坚持了一个小时
std::cout << sqr(x);