1

please note: this has been asked before

so I am trying speed to learn c++, since my clan have ddecided to start writing a game, but I have only done delphi, C#, java

Problem:

I have read through a few posts regarding this issue and as I understand I need to "overload the cout class" for use of the operator "<<" and ">>",

what is the reason for this, and isnt there a easier method for achieving this

the 2 operators (prob x) are giving the issue

// 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 Answers1

4

what is the reason for this

As already explained in the duplicates you admit exist, the reason is that you did not include the proper header that provides all the string functionality.

Half of it appeared to work by pure chance, because some other standard headers included little bits for you, in order to do their own work.

and isnt there a easier method for achieving this

No. Really, this could not be easier:

#include <string>

Write that.

That's it.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055