小编use*_*308的帖子

在简单的字符串代码中不匹配'operator =='

编写一个简单的代码并遇到问题我不知道如何处理.我试着通过搜索来调查它,但我找不到任何帮助,每个人的答案都有点高于我的头脑.请有人像小孩子一样解释这个,哈哈.谢谢.

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string invCode = "";
    string lastTwoChars = "";

    cout << "Use this program to determine color of furniture.";
    cout << "Enter five-character inventory code: ";
    cin >> invCode;

    if (invCode.length() == 5)
    {
        lastTwoChars = invCode.substr(3,2);
         if (lastTwoChars == 41)
         { 
              cout << "Red";
              }
         if (lastTwoChars == 25)
         { 
              cout << "Black";
              }
         if (lastTwoChars == 30)
         { 
              cout << "Green";
              }
    }
    else
         cout << "Invalid inventory …
Run Code Online (Sandbox Code Playgroud)

c++ string operator-keyword

0
推荐指数
1
解决办法
2768
查看次数

const char和二元运算符错误

首先要做的事情是:我知道这段代码过长,可能会缩短很多.但是,我不想要如何缩短它的帮助,我只是想了解一些基础知识,我现在的问题是运算符和存储值.正如您可以从代码中看到的那样,我试图使用一堆if语句在变量中存储特定值,然后在结尾处将这些值一起显示在字符串中.编译器不喜欢我的代码,并且给了我一堆与运算符相关的错误.

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string type = "";
    string color = "";
    string invTypeCode = "";
    string invColorCode = "";
    string fullCode = "";

    cout << "Use this program to determine inventory code of furniture.";
    cout << "Enter type of furniture: ";
    cin >> type;

    if (type.length() == 1)
    {
        if (type == "1" or "2")
        {
         if (type == "1")
         { 
              invTypeCode = "T47" << endl;
              }
         if (type == "2")
         { …
Run Code Online (Sandbox Code Playgroud)

c++ string operator-keyword operand

0
推荐指数
1
解决办法
389
查看次数

标签 统计

c++ ×2

operator-keyword ×2

string ×2

operand ×1