Jump to content

C++ help required

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Guest_theillbehaviored_*

Guest_theillbehaviored_*
  • Guests
Im making this single player MUD with C++ and I keep getting theese error messages

  • error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (
  • or there is no acceptable conversion)

  • error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (
  • or there is no acceptable conversion)

  • error C2447: missing function header (old-style formal list?)
  • Error executing cl.exe."

 


#include <iostream>

#include <fstream>

#include <string>

#include <C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\look.h>

#include <C:\Documents and Settings\Camper #1.IDKPPL\Desktop\MUD\info.h>

#include <ctime>

using namespace std;




ifstream a_file ("info.txt");



 

void sleep(unsigned int mseconds)

{

    clock_t goal = mseconds + clock();

    while (goal > clock());

}

int info(int EXP,int HP);

int look(int room);

int main()


{

HP = 100;

EXP = 0;

room = 1;

string name;

string command("look");


cout<<"Whats your name?";

cin>> name;

cout<<"Welcome "<< name <<"\n";


switch (command)

{ case 'look':

look(); break;

case 'info':

info();

break;} 

return 0; }


Can someone please assist me?

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
That looks like something may be corrupted in your #include files. It's not clear whether the error is in the code you provided or in look.h and info.h,
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Code Goddess

Code Goddess

    Newbie

  • Members
  • Pip
  • 9 posts
Excluding what I don't know about look.h and info.h, there's quite a bit wrong with your code:

>while (goal > clock());
A busy wait loop is extremely antisocial in a multitasking system.

>HP = 100;
>EXP = 0;
>room = 1;
Unless these guys are defined in one of your headers (which is a bad idea in the first place), they're undefined and you can't use variables without defining them.

>switch (command)
You can't do a switch on a string, only integral types.

>case 'look':
>case 'info':
These are character literals, not string literals. It's generally a bad idea to use multi-character character literals because they're implementation-defined unless you use very specific escape sequences.

>binary '>>' : no operator defined which takes a right-hand operand of type <string>
>binary '<<' : no operator defined which takes a right-hand operand of type <string>
These errors mean that operator << and operator >> don't recognize the type that you're using. Usually that means you forgot to qualify for the std namespace. With your code, that's not the case, but not knowing the contents of your headers makes it harder to determine the exact problem.