错误:二进制">>":未找到采用类型为"const char [1] 的右操作数的运算符

error : binary '>>' : no operator found which takes a right-hand operand of type 'const char [1]

本文关键字:gt char 运算符 操作数 const 二进制 类型 错误      更新时间:2023-10-16

>Mine是一个简单的c ++程序来计算圆的面积,但我得到这个错误。谁能帮我?我是 c++ 的新手。这是我的程序:

#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int area;
float r;
area = 3.14 * r * r;
cin >> "enter the radius" >> r;
cout << "Area of the circle is:" << area;
return 0;
}

您无法读文字"enter the radius"; 这就是编译器告诉你的:它试图写入该文字的第一个元素,即const char[1]类型。

您需要通过cout向用户显示该消息,就像输出区域时一样。然后使用

cin >> r;

在知道r之前,您也不应该评估area

(顺便说一下,你对pi的定义对于float类型来说是糟糕的:我倾向于使用atan(1)*4来表示pi;C++标准库没有为你定义它。