错误:与运算符 == 不匹配

2024-01-02

我的三个文件的多个区域都收到错误。 (我的默认构造函数也有问题,这就是它被注释掉的原因。但我想先解决这个问题)

// ComputerType.h
//************************************************************************
// This file gives the specification of a ComputerType abstract data type
//************************************************************************
//  #ifndef COMPUTERTYPE_H
    //  #define COMPUTERTYPE_H

      #include<fstream>
      #include<iostream>
      #include<iomanip>
      #include<string>
      #include<cctype>

      using namespace std;

      class ComputerType
      {
       public:

    //     ComputerType();
         //******************************************************************************
         // Default Constructor.
         // Purpose: Initialize the data by default value.
         // Input: None.
         // Precondition: None.

  ComputerType(int initID, string initPrcsr, string initRAMsize, string initDiskSize, string initCompType, float initcost, string initLab);
     //*******************************************************************************
     // Purpose: To initialize the data.
     // Input: InitID, initPrcsr, initRAMSize, initDiskSize, initCompType, initCost, initLab.
     // Precondition: initID, initPrcsr, initRAMSize, initDiskSize, initCompType, initCost, initLab have values.
     // Output: None.
     // PostCondition: Class object is constructed && Computer is set to incoming parameters.
     // Note: None.
     //********************************************************************************

     void SetComputer(int ID, string processorDesc, string RAM, string disk, string type, float compCost, string lab);
     //*******************************************************************************
     // Purpose: To set object data to value for use.
     // Input: ID, processorDesc, RAM, disk, type, compCost, lab.
     // Precondition: ID, processorDesc, RAM, disk, type, compCost, lab have values.
     // Output: None.
     // PostCondition: Object values are set to incoming parameters.
     // Note: None.
     //*******************************************************************************
 void SetComputerType(string& computerTypeConvert);
     //*******************************************************************************
     // Purpose: To set private data computerType to value for use.
     // Input: computerTypeConvert.
     // Precondition: typeConvert has value.
     // Output: None.
     // PostCondition: Object value computerType is set to incoming parameters.
     // Note: None.
     //*******************************************************************************

 string Processorls();
     //******************************************************************************
     //Purpose: Function Processorls returns the computer processor.
     //Input: None.
     //Pre: Object exists.
     //Output: string.
     //Post: processor is returned.
     //Note: None.
     //******************************************************************************

  string Locationls();
     //******************************************************************************
     //Purpose: Returns the computer.s lab location.
     //Input: None.
     //Pre: Object exists.
     //Output: string.
     //Post: string labLocation is returned.
     //Note:  None
     //******************************************************************************

     void ReadRd(ifstream& inFile);
     //******************************************************************************
     //Purpose: Function reads idNumber, processor, RAMSize, DiskSize, computerType,
     // cost, and labLocation from file, and assigns them to object variables.
     //Input: inFile.
     //Pre: inFile file open and OK.
     //Output: None.
     //Post: idNumber, processor, RAMSize, DiskSize, computerType, cost, and labLocation are stored from //file into object.
     //Note:  None.
  void PrintRd(ofstream& outFile);
     //******************************************************************************
     //Purpose: Function PrintRd prints idNumber, processor, RAMSize, DiskSize, computerType, cost and //labLocation to a file.
     //Input: outFile.
     //Pre: OutFile open and ok.
     //Output: float, string.
     //Post: function prints data to outFile.
     //Note:  none.
     //*****************************************************************************
  private:

     int idNumber;
     string processor;
     string RAMSize;
     string DiskSize;
     string computerType;
     float cost;
     string labLocation;
  };
//*****************************************************************************************

实施文件:

 //ComputerType.cxx
  //*********************************************************
  // This file implements the ComputerType member functions
  //*********************************************************
  #include "ComputerType.h"
  #include <iostream>
  #include <iomanip>
  #include <fstream>
  #include <cctype>
  #include <string>
  using namespace std;

  // Private members of class:
  // int idNumber;
  // string processor;
  // string RAMSize;
  // string DiskSize;
  // string computerType;
  // float cost;
  // string labLocation

//  ComputerType::ComputerType()
  //******************************************************************************
  // Default Constructor.
  // Purpose: Initialize the data by default value.
 // Precondition: None.
  // Output: None.
  // Postcondition: idNumber == -5555 && processor == NONE & RAMSize == Zero && DiskSize == Zero &&
  // computerType == NONE && cost == -777.00 && labLocation = NONE.
  // Note: None.
  //******************************************************************************
 // {
   // idNumber = -5555;
   // processor = "NONE";
   // RAMSize = "Zero";
   // DiskSize = "Zero";
   // computerType = "NONE";
   // cost = -777.00;
   // labLocation = "NONE";
 // }
  //***********************************************************************************8

  ComputerType::ComputerType(int initID, string initPrcsr, string initRAMSize, string initDiskSize, string initCompType, float initCost, string initLa$
  //*******************************************************************************
  // Purpose: To initialize the data.
  // Input: InitID, initPrcsr, initRAMSize, initDiskSize, initCompType, initCost, initLab.
  // Precondition: initID, initPrcsr, initRAMSize, initDiskSize, initCompType, initCost, initLab  have values.
  // Output: None.
  // PostCondition: Class object is constructed && private data is set to incoming parameters.
  // Note: None.
{
    idNumber = initID;
    processor = initPrcsr;
    RAMSize = initRAMSize;
    DiskSize = initDiskSize;
    computerType = initCompType;
    cost = initCost;
    labLocation = initLab;

  }
  //********************************************************************************

  void ComputerType::SetComputer(int ID, string processorDesc, string RAM, string disk, string type, float compCost, string lab)
  //*******************************************************************************
  // Purpose: To set object data to value for use.
  // Input: ID, processorDesc, RAM, disk, type, compCost.
  // Precondition: ID, processorDesc, RAM, disk, type, compCost, lab have values.
  // Output: None.
  // PostCondition: Object values are set to incoming parameters.
  // Note: None.
  //*******************************************************************************
  {
    idNumber = ID;
    processor = processorDesc;
    RAMSize = RAM;
 DiskSize = disk;
    computerType = type;
    cost = compCost;
    labLocation = lab;
  }
  //********************************************************************************

  void ComputerType::SetComputerType(string& computerTypeConvert)
  //*******************************************************************************
  // Purpose: To set private data computerType to value for use.
  // Input: typeconvert.
  // Precondition: typeConvert has value.
  // Output: None.
  {
    if(computerType == 'd' || computerType == 'D' || computerType == "desktop" || computerType == "Desktop" || computerType == "DESKTOP")
     {
       computerTypeConvert = "Desktop";
     }
    if(computerType == 'l' || computerType == 'L' || computerType == "laptop" || computerType == "Laptop" || computerType == "LAPTOP")
     {
      computerTypeConvert = "Laptop";
     }

    else
     computerTypeConvert = "Invalid input value";

    computerType = computerTypeConvert;
  }
  //*********************************************************************

  string ComputerType::Processorls()
  //******************************************************************************
  //Purpose: Function Processorls returns the computer processor.
  //Input: None.
  //Pre: Object exists.
  //Output: string.
 {
    return processor;
  }
  //******************************************************************************

  string ComputerType::Locationls()
  //******************************************************************************
  //Purpose: Returns the computer.s lab location.
  //Input: None.
  //Pre: Object exists.
 //Post: string labLocation is returned.
  //Note:  None.
  //******************************************************************************
  {
    return labLocation;
  }
  //******************************************************************************

  void ComputerType::ReadRd(ifstream& inFile)
  //******************************************************************************
  //Purpose: Function reads idNumber, processor, RAMSize, DiskSize, computerType, cost, and //labLocation from file, and assigns them to object variab$
  //Input: inFile.
  //Pre: inFile file open and OK.
  //Output: None.
  //Post: idNumber, processor, RAMSize, DiskSize, computerType, cost, and labLocation are stored from //file into object.
  //Note:  None.
  //******************************************************************************

  {
    int RAMSizeInt;
    string RAMSizeString;
    int DiskSizeString;
    string DiskSizeInt;

    inFile >> idNumber >> processor >> RAMSizeInt >> RAMSizeString >> DiskSizeInt >> DiskSizeString >> computerType >> cost >> labLocation;
 RAMSize = RAMSizeInt & RAMSizeString;
    DiskSize = DiskSizeInt & DiskSizeString;
  }
   //******************************************************************************

  void ComputerType::PrintRd(ofstream& outFile)
  //******************************************************************************
  //Purpose: Function PrintRd prints idNumber, processor, RAMSize, DiskSize, computerType, cost and //labLocation to a file.
  //Input: outFile.
  //Pre: OutFile open and ok.
  //Output: float, string.
  //Post: function prints data to outFile.
  //Note:  none.
 {
    outFile << setw(14) << idNumber << setw(25) << processor << setw(15) << RAMSize  << setw(18) << DiskSize;
    outFile << setw(19) << computerType << setw(9) << cost << setw(7) << labLocation << endl;
  }
   //*****************************************************************************

客户端代码:

 #include "ComputerType.h"
  #include <iostream>
  #include <fstream>
  #include <iomanip>
  #include <cctype>
  #include <string>
  using namespace std;

  int main()
  {
   // declare and open file streams
   ifstream inFile;
   ofstream outFile;

   inFile.open("in.data");
   outFile.open("out.data");
   outFile.setf(ios::fixed);
   outFile.precision(2);

   ComputerType rd;
   string computerTypeConvert;

   computertypeConvert = "type";


 // Check input file
  // if(inFile)
  // {
    // if(outFile)
    // {
     // while(inFile)
    // {
      // function calls for reading and assigning values to private data
      rd.ReadRd(inFile);
      rd.SetComputerType(computerTypeConvert);

      // Print to outFile
      outFile << setw(14) << "ID Number" << setw(25) <<  "P R 0 C E S S O R" << setw(15) << "RAM     Size";
      outFile << setw(18) << "Disk Size" << setw(19) << "Computer Type" << setw(9) << "Cost";
      outFile << setw(7) << "Location" << endl;
      rd.PrintRd(outFile);
    //  }
   return 0;
  }

这是我的错误列表:

 cxx -o runComputerType.out ComputerType.cxx runComputerType.cxx
ComputerType.cxx: In member function âvoid ComputerType::SetComputerType(std::string&)â:
ComputerType.cxx:95: error: no match for âoperator==â in â((ComputerType*)this)->ComputerType::computerType == 'd'â
ComputerType.cxx:95: error: no match for âoperator==â in â((ComputerType*)this)->ComputerType::computerType == 'D'â
ComputerType.cxx:99: error: no match for âoperator==â in â((ComputerType*)this)->ComputerType::computerType == 'l'â
ComputerType.cxx:99: error: no match for âoperator==â in â((ComputerType*)this)->ComputerType::computerType == 'L'â
ComputerType.cxx: In member function âvoid ComputerType::ReadRd(std::ifstream&)â:
ComputerType.cxx:156: error: no match for âoperator&â in âRAMSizeInt & RAMSizeStringâ
/usr/include/c++/4.3/bits/ios_base.h:81: note: candidates are: std::_Ios_Fmtflags std::operator&(std::_Ios_Fmtflags, std::_Ios_Fmtflags)
/usr/include/c++/4.3/bits/ios_base.h:121: note:                 std::_Ios_Openmode std::operator&(std::_Ios_Openmode, std::_Ios_Openmode)
/usr/include/c++/4.3/bits/ios_base.h:159: note:                 std::_Ios_Iostate std::operator&(std::_Ios_Iostate, std::_Ios_Iostate)
ComputerType.cxx:157: error: no match for âoperator&â in âDiskSizeInt & DiskSizeStringâ
/usr/include/c++/4.3/bits/ios_base.h:81: note: candidates are: std::_Ios_Fmtflags std::operator&(std::_Ios_Fmtflags, std::_Ios_Fmtflags)
/usr/include/c++/4.3/bits/ios_base.h:121: note:                 std::_Ios_Openmode std::operator&(std::_Ios_Openmode, std::_Ios_Openmode)
/usr/include/c++/4.3/bits/ios_base.h:159: note:                 std::_Ios_Iostate std::operator&(std::_Ios_Iostate, std::_Ios_Iostate)
runComputerType.cxx: In function âint main()â:
runComputerType.cxx:35: error: no matching function for call to âComputerType::ComputerType()â
ComputerType.h:32: note: candidates are: ComputerType::ComputerType(int, std::string, std::string, std::string, std::string, float, std::string)
ComputerType.h:17: note:                 ComputerType::ComputerType(const ComputerType&)

Since computerType is a string, its operator==()声明为与另一个字符串进行比较(用双引号括起来)"),而不是另一个字符(用单引号引起来').

Thus,

computerType == 'd' || computerType == 'D'

应该重写为

computerType == "d" || computerType == "D"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

错误:与运算符 == 不匹配 的相关文章

随机推荐

  • R:如何重新排序 ggplot2 线图中的图例键以匹配每个系列中的最终值?

    我正在使用 ggplot2 绘制折线图 显示多种工具的价格随时间的变化 我成功地在绘图上获得了多条线 并添加了显示最新价格变化的值 我想要做的 尚未实现 是对图例键重新排序 使涨幅最大的价格系列位于图例的顶部 其次是涨幅第二大的价格系列的键
  • 如何用Python解析SOAP XML?

    Goal 获取里面的值
  • XPath - 如何通过包含新行的@text进行选择

    在移动应用程序视图中 我看到如下文本 测试串 换行 但是在这个视图的元素树中 它看起来像可扩展的树查看器 我看到这个视图的 text 属性的值如下 用新行测试字符串 我尝试过使用以下方法 xpath text Test string nwi
  • Flutter.io Android 许可证状态未知

    gt Android toolchain develop for Android devices Android SDK 27 0 3 gt gt Android SDK a Android sdk Android NDK location
  • 使内容在 div 内水平滚动

    我有一个部门 我想在其中显示图像 然后单击在灯箱中打开它们 我将它们向左浮动并内联显示 设置overflow x滚动 但一旦行空间不够 它仍然将图像放在下面 我想让它们内联并在需要时显示水平滚动 NOTE 我无法改变里面图像的结构 它必须是
  • Git 日志表格格式

    我有一个简单的别名来显示最近的一些提交 log pretty format h an s 10 如何使结果显示在列中 如下所示 898e8789 Author1 Commit message here 803e8759 Other Auth
  • 使用 MiniTest 测试用户模型(设备身份验证)

    我正在尝试测试用户模型 为此我设计了身份验证 我面临的问题是 1 灯具中包含 密码 密码确认 字段会出现无效的 密码 密码确认 列错误 如果我从固定装置中删除这些列并添加到 user test rb require test helper
  • didFailToReceiveAdWithError 不适用于 iOS 8 模拟器

    我的 iAd AdMob 中介适用于所有 iOS 7 模拟器和设备 但是 iOS 8 didFailToReceiveAdWithError 方法不适用于任何模拟器 但适用于 iOS 8 设备 问题是我没有 iPhone 6 6 设备可供测
  • 包含动态“rgl”图的 HTML“knitr”文件在 RStudio 中无法正确显示

    在 Rstudio 中 我使用 rgl 包生成 3d 绘图 然后使用 knitr 将它们转换为用户可以交互的 html 文件 我遇到了几个我认为是独立的问题 但希望一次解决一个问题 万一它们不是 作为测试 我使用了来自网络的少量代码来生成绘
  • 如何在 VBA 访问中使用 SQL MERGE 语句?

    我一直在尝试在 Access 应用程序中使用 MERGE 语句 当我使用以下代码 为了便于阅读而简化 时 dim strSqlMerge as string strSqlMerge MERGE TargeTable AS T USING S
  • 无法从 START_OBJECT 令牌中反序列化 int[] 实例

    大家好 我想将 int 和 String 数组作为 RequestBody 发送 这是 json customUiModel 1 3 5 user user 这是端点代码 RequestMapping value save method R
  • 覆盖率测试工具 Django Rest Framework

    我正在研究 TDD 并在 Django Rest Framework 中开发 API 我研究了一个需求 但找不到一些工具来解决我的问题 我试图找出我的测试覆盖了我的应用程序的百分比 为了了解缺少封面的可能性和可能的 建议数量 我找到了cov
  • 如何将 EF Code-First 转换为 Database First?

    我想首先将我的代码优先项目转换为数据库 是否有一种自动化的方法 或者我应该删除实体和上下文代码并从创建的数据库创建模型 Entity Framework Power Tools 似乎支持一项名为 逆向工程代码优先 的功能 你可以下载它her
  • 使用 UTF8 编码将 Excel 转换为 CSV [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我有一个 Excel 文件 其中包含一些西班牙语字符 波形符等 我需要将其转换为 CSV 文件以用作导入文件 但是 当我 另存为 CSV
  • 如何解释C中命令行参数中的特殊字符?

    第一个问题 假设我们编写一个简单的程序 它接受命令行参数并打印到文件 如果用户输入 writetofile 你好 0 n w orl t y bash 回复 0 事件没有 成立 如果用户不知道使用引号 或转义字符 之类的东西 我该如何处理这
  • mcrypt 已被弃用,有什么替代方案?

    mcrypt 扩展名是已弃用 http php net manual en migration71 deprecated php migration71 deprecated ext mcrypt根据发布的评论 将在 PHP 7 2 中删除
  • 如何在SQL中按任意条件排序

    我有下表 CREATE TABLE Bable id int identity primary key name varchar 20 about varchar 30 INSERT INTO Bable name about VALUES
  • 检测android设备是否连接到互联网

    这是我的课程 用于检查设备是否连接到互联网 import android app Activity import android content Context import android net ConnectivityManager
  • React:我可以在渲染之前检查状态是否存在吗

    我是 React 新手 我制作了一个显示用户名 user 的导航栏
  • 错误:与运算符 == 不匹配

    我的三个文件的多个区域都收到错误 我的默认构造函数也有问题 这就是它被注释掉的原因 但我想先解决这个问题 ComputerType h This file gives the specification of a ComputerType