基本代码中的"运算符=不匹配"错误

'No match for operator=' error in basic code

本文关键字:运算符 不匹配 错误 代码      更新时间:2023-10-16

我对编码很陌生(就像一天前一样),所以你可以假设我什么都不知道。我发现调试我极其简单的程序非常困难,我在网上看到的大多数帮助要么超出了我的想象,要么过于针对程序。

这就是我现在正在编写的代码。

/*
 * LogBase8.cpp
 *
 *  Created on: Feb 13, 2015
 *      Author: Holly
 */
//This program calculates the log base 8 of a number.
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
//Declare variables and constants.
float x, log_8_x;
int main()
{
//Prompt user to input number.
cout << "This program will calculate the log base 8 of a number. Input number to calculate" << endl;
cin >> x;
//Calculate log_8_x.
log_8_x = log(x) / log(8);
//Print log_8_x.
cout << "The log base 8 of " << x << " is " << log_8_x << endl;
//End main.
return (0);
}

我在log_8_x = log(x) / log(8);行中有一个错误,上面写着

no match for 'operator=' (operand types are 'std::basic_istream<char>::__istream_type {aka std::basic_istream<char>}' and 'double') 

如果相关的话,我正在使用Eclipse。

正如问题中所述,您还有其他错误,但无论如何都要放一个来转义字符串中出现的换行符

cout << "This program will calculate the log base 8 of a number. Input 

修复编译错误。

请在这里查看完整的工作样本。