i get this error on any line with dot notation. Oh, and do I need to use
cin.getline(boy .name)?:
error:'.':left operand points to 'struct' use '->'
This is the program in question:
#include<iostre am.h>
#include<string .h>
#define MAX 20
#define ARRAY 4
struct monkey {
char name[MAX];
int age;
float weight;
};
void main()
{
struct monkey boy[ARRAY];
int index;
for(index=0; index<ARRAY; index++)
{
cout<<"MONKEY BOY "<<(index+1 )<<" :"<<endl;
cout<<"Enter the name: ";
cin>>boy.name;
cout<<endl<<"En ter the age: ";
cin>>boy.age;
cout<<endl<<"En ter the weight: ";
cin>>boy.weight ;
cout<<endl<<end l;
}
}
Does anybody know what is wrong? 9 5707
Acacia wrote: i get this error on any line with dot notation. Oh, and do I need to use cin.getline(boy .name)?:
error:'.':left operand points to 'struct' use '->'
This is the program in question:
#include<iostre am.h>
#include <iostream> // no '.h' -- see the FAQ (link below) #include<string .h>
// #include <string> or <cstring>... hard to tell which you need,
// because you're not actually using either.
using std::cout; // or, just 'using namespace std;
using std::end;
using std::cin; #define MAX 20
const unsigned int MAX = 20 // see the FAQ #define ARRAY 4
const unsigned int ARRAY = 4; struct monkey { char name[MAX];
// use std::string -- see the FAQ int age; float weight; };
void main() {
struct monkey boy[ARRAY];
You could use a std::vector here -- again, see the FAQ
int index;
for(index=0; index<ARRAY; index++) {
cout<<"MONKEY BOY "<<(index+1 )<<" :"<<endl; cout<<"Enter the name: "; cin>>boy.name;
// 'boy' is of type 'struct monkey []', which is an array.
// You should have this instead:
cin >> boy[index].name
cout<<endl<<"En ter the age: "; cin>>boy.age; cout<<endl<<"En ter the weight: "; cin>>boy.weight ; cout<<endl<<end l;
}
}
Does anybody know what is wrong?
You really need to read the FAQ: http://parashift.com/c++-faq-lite/
- Adam
"Acacia" <ne*******@fatg erbil.co.uk> wrote in message news:bi******** ***********@new s.demon.co.uk.. . cin>>boy.name;
boy is an array, you have to specify a particular element
cin >> boy[index].name;
Does anybody know what is wrong?
#include<iostre am>
#include<string >
#define MAX 20
#define ARRAY 4
struct monkey
{
char name[MAX];
int age;
float weight;
};
int main(int,char** )
{
monkey boy[ARRAY];
for(int index=0;index<A RRAY;index++)
{
std::cout<<"\nM ONKEY BOY "<<(index+1 )<<" :";
std::cout<<"\nE nter the name: ";
std::cin>>boy[index].name;
std::cout<<"\nE nter the age: ";
std::cin>>boy[index].age;
std::cout<<"\nE nter the weight: ";
std::cin>>boy[index].weight;
std::cout<<"\n\ n";
}}
-X
"Agent Mulder" wrote: #include<iostre am> #define MAX 20
struct monkey { char name[MAX]; }; ... monkey boy[ARRAY]; ... std::cin>>boy[index].name;
cin.operator>>( char*) is unsafe.
Use std::string or
std::cin >> std::setw(MAX) >> boy[index].name;
HTH,
Patrick
I think it was the array that did it. After posting i tried
boy.name[index]
after realising i hadn't stated with element of the array to use, which
didn't work. I have just tried with
boy[index].name
and it works. i don't really understand most of what you said, but I looked
at the FAQ and it confuses me as it is very different from the book I am
learning basic c++ from (a complete idiots guide to c++ (Paul Snaith)) but
the array thing has fixed my problem. I will now attempt to use functions to
achieve this same outcome, then save the information in a binary file (no,
don't help me with this yet - i need to work it out). Also, emitting the
..h
from
iostream.h
returns an arror. I am using MSVC (v1.52).
Thanks for your help.
"Adam Fineman" <aB************ **@KcIoNmGpSute r.org> wrote in message
news:GK******** *********@news. uswest.net... Acacia wrote: i get this error on any line with dot notation. Oh, and do I need to use cin.getline(boy .name)?:
error:'.':left operand points to 'struct' use '->'
This is the program in question:
#include<iostre am.h> #include <iostream> // no '.h' -- see the FAQ (link below) #include<string .h> // #include <string> or <cstring>... hard to tell which you need, // because you're not actually using either.
using std::cout; // or, just 'using namespace std; using std::end; using std::cin;
#define MAX 20
const unsigned int MAX = 20 // see the FAQ #define ARRAY 4 const unsigned int ARRAY = 4;
struct monkey { char name[MAX];
// use std::string -- see the FAQ int age; float weight; };
void main() {
struct monkey boy[ARRAY];
You could use a std::vector here -- again, see the FAQ
int index;
for(index=0; index<ARRAY; index++) {
cout<<"MONKEY BOY "<<(index+1 )<<" :"<<endl; cout<<"Enter the name: "; cin>>boy.name;
// 'boy' is of type 'struct monkey []', which is an array. // You should have this instead:
cin >> boy[index].name
cout<<endl<<"En ter the age: "; cin>>boy.age; cout<<endl<<"En ter the weight: "; cin>>boy.weight ; cout<<endl<<end l;
}
}
Does anybody know what is wrong?
You really need to read the FAQ: http://parashift.com/c++-faq-lite/
- Adam
"Acacia" <ne*******@fatg erbil.co.uk> wrote in message
news:bi******** ***********@new s.demon.co.uk.. . I think it was the array that did it. After posting i tried
boy.name[index]
after realising i hadn't stated with element of the array to use, which didn't work. I have just tried with
boy[index].name
and it works. i don't really understand most of what you said, but I
looked at the FAQ and it confuses me as it is very different from the book I am learning basic c++ from (a complete idiots guide to c++ (Paul Snaith)) but the array thing has fixed my problem. I will now attempt to use functions
to achieve this same outcome, then save the information in a binary file (no, don't help me with this yet - i need to work it out). Also, emitting the
.h
from
iostream.h
returns an arror. I am using MSVC (v1.52).
Thanks for your help.
One of the hazards for newbies posting to c.l.c++ is that they can get the
answers to a whole load of questions they didn't ask. Its ironic that the
compiler you are using is so old that much of the advice was impossible for
you to follow anyway. If it is possible you should think about upgrading
your compiler, the language you will learn by using VC++ 1.52 is somewhat
different from true C++.
I'm glad you figured it out for yourself, best way to learn.
john
Where can I get hold of a newer compiler? I would like to learn C++ - but
upon visting this newsgroup it seems far more complex than I previously
thought........ .
"Acacia" <ne*******@fatg erbil.co.uk> wrote in message
news:bj******** ***********@new s.demon.co.uk.. . Where can I get hold of a newer compiler? I would like to learn C++ - but upon visting this newsgroup it seems far more complex than I previously thought........ .
Well you can buy one. Microsoft do a learning edition of their compiler for
a moderate price. Easy to use, nice IDE.
If you want a free one, then get hold of gcc, from http://gcc.gnu.org/. Just
as good a compiler (better probably) but without the slick interface.
john
"John Harrison" <jo************ *@hotmail.com> wrote in message
news:bj******** ****@ID-196037.news.uni-berlin.de... "Acacia" <ne*******@fatg erbil.co.uk> wrote in message news:bj******** ***********@new s.demon.co.uk.. . Where can I get hold of a newer compiler? I would like to learn C++ -
but upon visting this newsgroup it seems far more complex than I previously thought........ .
Well you can buy one. Microsoft do a learning edition of their compiler
for a moderate price. Easy to use, nice IDE.
If you want a free one, then get hold of gcc, from http://gcc.gnu.org/.
Just as good a compiler (better probably) but without the slick interface.
john
Actually gcc for Windows is probably better obtained from here http://www.cygwin.com.
john This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Joh |
last post by:
hello,
i'm trying to understand how i could build following consecutive sets
from a root one using generator :
l =
would like to produce :
, , , ,
|
by: Robert Mark Bram |
last post by:
Howdy All!
Is there any difference between referencing objects and attributes with dot
notation or bracket notation?
Example,
document.formname.controlname
document
Can I access attributes and objects equally with both?
|
by: Robert Lapes |
last post by:
I'm just getting into using CSS and I'm having a problem getting Opera
to display a Navigation Bar in the same way as IE6. Can someone
please point me in the right direction?
The site I'm working on can be seen at
http://www.budbury.co.uk/itel/index.htm
In Opera 6.05 the Nav Bar image floats behind the content division that
follows the navbar.
|
by: Thomas Lorenz |
last post by:
Hello,
I'm a little confused about object initialization. According to Stroustrup
(The C++ Programming Language, Special Edition, Section 10.2.3) constructor
arguments should be supplied in one of the following notations:
MyClass instance1 = MyClass(1, 2, 3);
MyClass instance2(4, 5, 6);
What's curious: the second notation variant is called an "abbreviated form"
|
by: Harry |
last post by:
Hi ppl
Some problem regarding pointer:
ULONG *addr;
CHAR *ptr=NULL;
addr=new ULONG;
//calling a function and getting the addr value
//ULONG is 4 bytes. I am getting the Ip address which is naturally 4
| |
by: Mike Bridge |
last post by:
Hi-
I've created an XHTML extension module which validates correctly using the W3C online schema validator, but fails when
I use the .net 1.1 validator. It seems to be choking on an included W3C file:
http://www.w3.org/MarkUp/SCHEMA/xhtml-notations-1.xsd
The problem seems to be on this line:
<xs:notation name="cdata" public="-//W3C//NOTATION XML 1.0: CDATA//EN" />
|
by: Michel Rouzic |
last post by:
I obtain an unwanted behavior from the pow() function :
when performing pow(2, 0.5), i obtain 1.414214
when performing pow(2, 1/2), i obtain 1.000000
when performing a=0.5; pow(2, a), i obtain 1.414214
when performing a=1/2; pow(2, a), i obtain 1.000000
how come??? and how can i do a pow(x, y) so my y is the fraction of two
other variables? (cuz for now it acts as if that fraction of two
variables in y was truncated)
|
by: Suresh |
last post by:
Hi Guys
I have Db2 server installed on remote server. i am connecting to that
remote server by using VPN.
I want to connect that remote DB2 server instance using my local
machine DB2 development client. Bur Its gives me following error
message. I searched lots of things on net and tried on remote server
but i didnt got suceess. Can any one tell me how to set TCP\IP
connection protocol on server for particular instance. Becuase I think
|
by: Suresh |
last post by:
Hi Guys
I have Db2 server installed on remote server. i am connecting to that
remote server by using VPN.
I want to connect that remote DB2 server instance using my local
machine DB2 development client. Bur Its gives me following error
message. I searched lots of things on net and tried on remote server
but i didnt got suceess. Can any one tell me how to set TCP\IP
|
by: Christophe Charron |
last post by:
Hi,
is there a known bug on php 5.2.4 in wamp5 (http://www.wampserver.com/
en/index.php) about having different kinds of printing for some
numeric values.
This script works perfectly on an linux based server on internet but
doesn't on my local wamp5. (here is the screnshot)
http://test03.christophe-charron.org/public/php/2007_09_20/2007-09-22-qte_bizarre_b.png
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |