(错误C2678)错误:无操作符“<<”匹配这些操作数

时间:2014-01-11 17:27:05

标签: c++ operator-overloading std

请注意:此问题已在

之前提出

所以我正在努力学习c ++,因为我的家族已经决定开始编写游戏,但我只做了delphi,C#,java

问题:

我已阅读了一些有关此问题的帖子,据我所知,我需要“重载cout类”以使用运算符“<<”和“>>”,

这是什么原因,并没有更简单的方法来实现这个

2个运营商(问题x)正在提出问题

// Custom.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <Windows.h>


int _tmain(int argc, _TCHAR* argv[])
{
    using namespace std;

        double input, out;
        string degtype;

        cin /*>> "What is the temperature: "*/ >> input;
        cin /*>> "Convert to [C]elsius or [F]ahrenheit?: " */ [(prob1)>>] degtype;

        if (degtype.compare("C") == 0 || degtype.compare("c") == 0)
        {
            out = (-32 - (input * 1.8)) + input;
            degtype = "Celcius";
        }
        else
            if (degtype.compare("F") == 0 || degtype.compare("f") == 0)
        {
            out = 32 + (input * 1.8);
            degtype = "Fahrenheit";
        }

            cout << "The " [(prob 2)<<] degtype << "value is " << out;


}

1 个答案:

答案 0 :(得分:4)

  

这是什么原因

正如您承认存在的重复项中所述,原因是您没有包含提供所有string功能的正确标头。

其中一半似乎只是纯粹的机会,因为一些其他标准标题包含了一点点,为了做自己的工作。

  

并没有更简单的方法来实现这个

没有。真的,这可不容易:

#include <string>

写下来。

就是这样。

相关问题