left hand opperand??

This is a discussion on left hand opperand?? within the C++ Programming forums, part of the General Programming Boards category; can some one help me with what im doing wrong here....... somthing about a left hand opperand? Code: struct weapon ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    57

    Question left hand opperand??

    can some one help me with what im doing wrong here.......
    somthing about a left hand opperand?

    Code:
    struct weapon
    {
    	char name[15];
    	char Wclass[6];
    	char type[6];
    	int damage;
    	int plusToDamage;
    	int toHit;
    	int plusToHit;
    	int cost;
    };
    int main(int argc, char* argv[])
    {
    
    	weapon broadSword;
    
    	broadSword.name = "Sword of Might";
    	broadSword.Wclass = "sword";
    	broadSword.type = "slash";
    	broadSword.damage = 13;
    	broadSword.plusToDamage = 3;
    	broadSword.toHit = 52;
    	broadSword.plusToHit = 3;
    	broadSword.cost = 25;
    
    	cout << broadSword.name << endl;
    	cout << broadSword.damage << endl;
    	cout << broadSword.cost << endl;
    	cout << endl;
    	
    	
    	return 0;
    }
    =@-OmegatronO-@=

  2. #2
    biz
    biz is offline
    Registered User
    Join Date
    Mar 2002
    Posts
    14

    Re: left hand opperand??

    You are missing iostream[.h]

    Code:
    #include <iostream.h>
    
    struct weapon
    {
    	char name[15];
    	char Wclass[6];
    	char type[6];
    	int damage;
    	int plusToDamage;
    	int toHit;
    	int plusToHit;
    	int cost;
    };
    int main(int argc, char* argv[])
    {
    
    	weapon broadSword;
    
    	broadSword.name = "Sword of Might";
    	broadSword.Wclass = "sword";
    	broadSword.type = "slash";
    	broadSword.damage = 13;
    	broadSword.plusToDamage = 3;
    	broadSword.toHit = 52;
    	broadSword.plusToHit = 3;
    	broadSword.cost = 25;
    
    	cout << broadSword.name << endl;
    	cout << broadSword.damage << endl;
    	cout << broadSword.cost << endl;
    	cout << endl;
    	
    	
    	return 0;
    }

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    57
    ahh no
    sorry i did have that in my orignal code i just posted the struct stuff
    =@-OmegatronO-@=

  4. #4
    biz
    biz is offline
    Registered User
    Join Date
    Mar 2002
    Posts
    14
    Well it compiles fine on my system after I include iostream.h

    *shrug*

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    57
    ummm also i was wondering.....my three char arrays ..well is there a way i can hold any size array instead of the predefined amounts i have

    thanx!


    these are my errors:

    C:\Program Files\Microsoft Visual Studio\MyProjects\structs2\structs2.cpp(25) : error C2106: '=' : left operand must be l-value
    C:\Program Files\Microsoft Visual Studio\MyProjects\structs2\structs2.cpp(26) : error C2106: '=' : left operand must be l-value
    C:\Program Files\Microsoft Visual Studio\MyProjects\structs2\structs2.cpp(27) : error C2106: '=' : left operand must be l-value
    Last edited by Megatron; 03-27-2002 at 05:39 PM.
    =@-OmegatronO-@=

  6. #6
    biz
    biz is offline
    Registered User
    Join Date
    Mar 2002
    Posts
    14
    There are a few ways to hold different sized arrays of strings in memory. Two off the top of my head:
    a1) If I recall correctly, many compilers as of late include some sort of string class which handles all of this for you
    a2) look up the operators "new" and "delete" for explanations on dynamic memory allocation.

  7. #7
    biz
    biz is offline
    Registered User
    Join Date
    Mar 2002
    Posts
    14

    Re: Re: left hand opperand??

    Try this:

    Code:
    #include <iostream.h>
    #include <string.h>
    
    struct weapon
    {
    	char name[15];
    	char Wclass[6];
    	char type[6];
    	int damage;
    	int plusToDamage;
    	int toHit;
    	int plusToHit;
    	int cost;
    };
    int main(int argc, char* argv[])
    {
    
    	weapon broadSword;
    
    	strcpy(broadSword.name,"Sword of Might");
    	strcpy(broadSword.Wclass,"sword");
    	strcpy(broadSword.type,"slash");
    	broadSword.damage = 13;
    	broadSword.plusToDamage = 3;
    	broadSword.toHit = 52;
    	broadSword.plusToHit = 3;
    	broadSword.cost = 25;
    
    	cout << broadSword.name << endl;
    	cout << broadSword.damage << endl;
    	cout << broadSword.cost << endl;
    	cout << endl;
    	
    	
    	return 0;
    }
    *edited for typos*
    Last edited by biz; 03-27-2002 at 05:47 PM.

  8. #8
    Registered User
    Join Date
    Aug 2001
    Posts
    57
    ahh yes that works nicely

    thanks very much!!



    ya i caught that
    lol
    =@-OmegatronO-@=

  9. #9
    biz
    biz is offline
    Registered User
    Join Date
    Mar 2002
    Posts
    14
    no problem...hehe yea...I am the typo master

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Odd 3D Invis Objects?
    By Zeusbwr in forum Game Programming
    Replies: 4
    Last Post: 12-07-2004, 07:01 PM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  3. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Please help me
    By teedee46 in forum C++ Programming
    Replies: 9
    Last Post: 05-07-2002, 12:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21