我是C++新手,目前我正在学习void函数。 我正在尝试使用void函数编写一个方形数字的函数。这是我的代码。C++ void函数练习错误
#include "std_lib_facilities.h"
void square(int);
int main()
{
int x = 0;
cout << "Please enter a number. It will be squared.";
cin >> x;
cout << x << 't' << square(x);
}
void square(int x)
{
int y = x*x;
cout << y;
}
的IDE给我的错误是:
no match for 'operator<<' (operand types that are 'std::basic_ostream<char>'
and 'void')
从经验来说,很多人会问的头文件std_lib_facilities.h
,这是没有问题的。我可以这么说,因为我使用这个头文件进行了很多练习,并且他们都工作了。
非常感谢您的帮助!
您正试图打印调用该函数的结果。 – chris